[Solved] Big O Of Mod 20

Assuming that you can insert integers of any size, the complexity will be the same as the complexity of division. So it is O(log n) due to log n is the number of digits. Notice 1: If you can only insert 32 or 64 bit integers, the “complexity” will be O(1). Notice 2: Since computers … Read more

[Solved] Competition Problem: Finding numbers containing “2020” from 1 to N which is a multiple of 2020 faster than O(N/2020) [closed]

If you get stuck here’s a solution import math baseInt = 2020 #This is the int you want to find within the other int randomInt = 1012020 #This is the int you’re going to count up to def checkBaseInt(baseInt, theIteratorInt): theNumString = str(theIteratorInt) #Converting to strings to find the substring baseIntString = str(baseInt) if(theNumString.find(baseIntString) == … Read more

[Solved] How can i reduce the time complexity of this program?

Almost all that this code do is organizing input and output except only this line: count=Collections.frequency(list,x); This is the only line where real computations happen. Actually, it’s time and space complexity is determined by the standard java.util.Collections.frequency method which should have pretty good time and space characteristics for such a trivial case. 1 solved How … Read more

[Solved] time complexity for following function

Upto my knowledge, most common time complexity notation is Big-O, I’ll share same in this answer. Time complexity is O(1), with an assumption that Math.Pow calculation is O(1) and .ToString() method is O(1). It is O(1) because each step will be executed only once. In gerenal, if we take .ToString().Length time complexity into account then … Read more

[Solved] Analysis complexity, in for inside for, the 2nd for depeneds from the first one [closed]

Introduction Analysis complexity is an important concept in computer science, as it helps to determine the efficiency of algorithms. In particular, the analysis of complexity in a for inside for loop is important, as the complexity of the second for loop depends on the first one. This article will discuss the analysis of complexity in … Read more

[Solved] Big O Notation/Time Complexity issue

It would be O(N). The general approach to doing complexity analysis is to look for all significant constant-time executable statements or expressions (like comparisons, arithmetic operations, method calls, assignments) and work out an algebraic formula giving the number of times that they occur. Then reduce that formula to the equivalent big O complexity class. In … Read more

[Solved] Searching Duplicate String Complexity

You are making your code way too complicated, use a HashSet<String>, which will guarantee uniqueness and will return whether the element was already in the set. public class DuplicateEle { public static void main(String args[]) { Set<String> seen = new HashSet<>(); String[] arr = { “hello”, “hi”, “hello”, “howru” }; for (String word : arr) … Read more