I am finding a solution either in python or java to find the intersection between 2 lists. In python, we can use (sets/lists) etc In java, we can use (ArrayList) etc Or we can use HashSet also. But I am not able to understand which approach should we use. In hash sets, we have less ..

#### Category : time-complexity

Say we use 2 functions in one go: sorted(list(str_variable)) – Python uses Timsort which has a complexity of NlogN – so then the overall complexity of this becomes: N^2*logN It’d be considered as a function inside a function and so the complexities will get multiplied (O(N) for list() and O(NlogN) for the sort(). But I ..

I am trying to find no of combinations possible using given array elements which is less than given no n. Example : Input: digits = ["1","3","5","7"], n = 100 Output: 20 The 20 numbers that can be written are: 1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, ..

Code total_exc_time = 0 for _ in range(10): start = time.time() set_a = set() dict_a = dict() add = set_a.add for index in range(1000000): dict_a[index] = index add(index) total_exc_time += ((time.time() – start) * 1000) total_exc_time = 0 for _ in range(10): `start = time.time()` `dict_a = dict()` for index in range(1000000): dict_a[index] = index ..

This code computes a^b.. But I am not sure about its complexity def powerFunc(a,b): if b==1: return a elif b==0: return 1 else: return a*powerFunc(a,b-1) a=int(input()) b=int(input()) print(powerFunc(a,b)) Source: Python-3x..

If there are no other loops inside of that while loop, is it possible to have O(n^2) runtime? Source: Python..

For a set. What is the time complexity for next(iter(S))? Any proof? I know that iter() turns an iterable into iterator and suppose next() is O(1). Source: Python-3x..

Here’s my code: def isIso(x,y): if len(x) != len(y): return False for i in range(len(x)): count = 0 if x.count(x[i]) != y.count(y[i]): return False return True Why do all solutions for this question online involve mapping or dictionaries? I’m wondering why everyone seems to be overcomplicating the solution to this problem. Is it a time ..

So I’ve been studying algorithms for a coding test and I’ve come across an interesting problem. The problem asks to implement an algorithm that takes an integer as an input and converts it into the string equivalent. First, it asks from (0-999) then (0-999,999,999). The only way I can think of answering the problem is ..

Given a palindromic string palindrome, replace exactly one character by any lowercase English letter so that the string becomes the lexicographically smallest possible string that isn’t a palindrome. After doing so, return the final string. If there is no way to do so, return the empty string. I have come up with the following, which ..

## Recent Comments