← CS Fundamentals
#1 most askedVery commonEasyComplexity

What's the Big-O of this code?

New to Complexity? Learn it from scratch first
Big-O in Plain English →
šŸ¢ Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

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 →