Issue I am working on a coding problem in which I have to delete all occurrences of a substring T in a string S (keeping in mind that removing one occurrence of T in S may generate a new occurrence
Continue readingTag: time-complexity
[SOLVED] Time complexity of casting lists to tuples in python and vice versa
Issue what is the time complexity of converting a python list to tuple (and vice versa): tuple([1,2,3,4,5,6,42]) list((10,9,8,7,6,5,4,3,1)) O(N) or O(1), i.e. does the list get copied or is something somewhere internally switched from writable to read-only? Thanks a lot!
Continue reading[SOLVED] Improving Time Efficiency on two custom List in KOTLIN
Issue There are two lists: val listA:List<Amodel> val listB:List<Int> data class Amodel(val id:Int,var isUsed:Boolean=false) Need to update listA isUsed =true based on the int id of the listB What I’m doing now: listB.foreach(){ //here i’m updating but it’s taking too
Continue reading[SOLVED] In JavaScript, from two array of objects I need to filter out objects based on a filter condition, in a new array in complexity less than O(n^2)
Issue Explanation of the problem statement : I have two arrays A and B : A = [ { "isAvailable" : true, "productCode" : "12103977", "size" : "UK/IND-3", "url" : "/asics-mens-gel-kayano-28-harmony-blue-running-shoes/12103977" }, { "isAvailable" : true, "productCode" : "12103978", "size"
Continue reading[SOLVED] What is the time complexity of heapq.nlargest?
Issue I was looking at this pycon talk, 34:30 and the speaker says that getting the t largest elements of a list of n elements can be done in O(t + n). How is that possible? My understanding is that
Continue reading[SOLVED] Finding time complexity of this loop?
Issue What’s time complexity of this loop? R = 40; while(R>=10){ x = x-1; R = R div 2; } I really appreciate if you explain it to me, too. Solution Each cycle the R is reduced to half. Therefore
Continue reading[SOLVED] What is the time complexity for this generic bruteforce/backtracking function?
Issue I am having trouble reasoning what the time complexity of this is. I was writing a backtracking function to solve a problem. To simplify, let’s just say I have a list of size "a" and I am allowed to
Continue reading[SOLVED] Time complexity of loop multiplying the value by two or three
Issue I found the below for-loop in an SO question. I found that the time complexity is O(n log n). How would I find the time complexity if we change k *= 2 to k *= 3? // ‘int n’
Continue reading[SOLVED] Check if array is sorted using O(1)
Issue Is it possible to check (in Java) if an array is sorted or not with O(1) worst time complexity? Solution It’s impossible to have a correct algorithm with better than O(n) complexity. Let’s prove it by contradiction. If are
Continue reading[SOLVED] Identifying the basic operation of an algorithm
Issue I am currently studying an algorithms unit at university and I can’t seem to get a clear answer from anyone about determining the basic operation of an algorithm. I understand it can occur in more than one place, but
Continue reading