#1 most askedVery commonEasyComplexity
What's the Big-O of this code?
New to Complexity? Learn it from scratch firstBig-O in Plain English ā
š¢ Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.Predict the output, then give the time complexity of each function in terms of n.
š® Predict the output
def steps_halving(n):
count = 0
while n > 1:
n //= 2
count += 1
return count
def steps_pairs(n):
return sum(1 for i in range(n) for j in range(i + 1, n))
print(steps_halving(1024), steps_pairs(5))
š¤ Answer it out loud, then check yourself
Say your answer as if the interviewer is listening (30ā90 seconds). Then reveal what a strong answer covers and tick what you said.
Answer out loud first, then compare.
Want to rehearse it?Answer this to the AI interviewer and get a verdict ā