🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Time & Space Complexity Quiz: all 8 questions

Time & Space Complexity Quiz · Question 2 of 8

What is the time complexity of this code? (code)

What is the time complexity of this code?

for i in range(n):
    print(i)
for j in range(n):
    print(j)
  1. A.O(n)
  2. B.O(n²)
  3. C.O(2ⁿ)
  4. D.O(log n)
Answer & explanation

Correct answer: O(n)

Sequential loops add: n + n = 2n, and we drop the constant → O(n).

Can you get the rest right without peeking?

Take the timed Time & Space Complexity Quiz quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →