← Time & Space Complexity Quiz: all 8 questions
Time & Space Complexity Quiz · Question 1 of 8
What is the time complexity of this code? (code)
What is the time complexity of this code?
for i in range(n):
for j in range(n):
print(i, j)
- A.O(n)
- B.O(2n)
- C.O(n²)
- D.O(n log n)
Answer & explanation
Correct answer: O(n²)
The inner loop runs n times for each of the n outer iterations: n × n = 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 →