Skip to content
Advertisement

Tag: algorithm

Find the indices where a sorted list of integer changes

Assuming a sorted list of integers as below: I want to find the indices where the values changes, i.e. One approach is to use itertools.groupby: Output This approach is O(n). Another possible approach is to use bisect.bisect_left: Output This approach is O(k*log n) where k is the number of distinct elements. A variant of this approach is to use an

What is Big O in this example of code, O(N) or O(N^2)?

Can you please explain what is Big O in this example of code? Answer It depends entirely on your definition of n. If you define n to be the number of cells in the 2d matrix, then this nested loop is of linear complexity O(n) in relation to it. On the other hand, if you define n to be the

Appending item on same index

I have these indexes: [3,1,1,2] which shows position for every element in the first list And I need to append these items to that corresponding indexes: to list, to be like in this particular order, so after the item is inserted on the index and the next item is again pointing to the same position, the first added moves to

Palindrome question use of lambda and key

Hey guys so I was working on this problem on the algoExpert platform, but I am struggling to understand what longest and currentLongest are really doing. Just from the beginning, I am not entirely sure what the currentLongest = [0, 1] is doing, is it just saying that it will have 2 values? Are odd and even returning an array

Finding MACD Divergence

I want to create a loop to automate finding MACD divergence with specific scenario/criterion, but I am finding it difficult to execute although its very easy to spot when looking at chart by eyes. Note: you can easily get this as ready available scanner but i want to improve my python knowledge, hope someone will be able to help me

Advertisement