0

i want to known the time complexity of this code python3 code :

def twoStacks(maxSum, a, b):
    # Write your code here
    sum_all=0
    times=-1
    while sum_all<maxSum:
        if a[0]<b[0] and len(a)>0 and len(b)>0 or len(a)>0 and len(b)==0:
            poped_a=a.pop(0)
            sum_all=sum_all+poped_a
            times=times+1
        elif a[0]>b[0] and len(a)>0 and len(b)>0 or len(b)>0 and len(a)==0:
            poped_b=b.pop(0)
            sum_all=sum_all+poped_b
            times=times+1
    return times
  • Can you ask a more specific question about calculating the time complexity? Is it that you can't figure out the number of times the `while` loop executes? Or you don't know the complexity of the `if/elif` statement? – Raymond Chen Jul 26 '21 at 17:46
  • its about the while loop as well as the inbuilt functions complexity like pop() and len() – Aditya Salabh Jul 26 '21 at 17:52
  • Does this answer your question? [What is the runtime complexity of python list functions?](https://stackoverflow.com/questions/1005590/what-is-the-runtime-complexity-of-python-list-functions) – Raymond Chen Jul 26 '21 at 17:58
  • no, i need exact time complexity of this code – Aditya Salabh Jul 26 '21 at 19:26
  • Please be specific what your question is. Is it that you cannot calculate how many iterations are run? What have you calculated so far? – Raymond Chen Jul 27 '21 at 00:54

0 Answers0