Count how many times a single loop over five items runs.
Acceptance criteria
- 1.#out should show five steps.
DSA Tutorial · Big O and Complexity
These 10 tasks go with the Big O Notation Explained chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Big O does not tell you how fast your code is. It tells you how much worse it gets when the input grows — which is the thing that actually breaks in production.” .
1.Count a single passexercise · easy · 10 min
Count how many times a single loop over five items runs.
Passes when: #out should show five steps.
2.Count a nested passexercise · easy · 10 min · practice plan
Count the iterations of two nested loops over three items each.
Passes when: #out should show nine steps.
3.Name the growthexercise · easy · 10 min · practice plan
A loop that halves the range each time — report its growth as logarithmic or linear.
Passes when: #out should show logarithmic.
4.Drop the constantexercise · easy · 10 min · practice plan
Report the simplified class of 3n + 5, as the word linear or quadratic.
Passes when: #out should show linear.
5.Constant time lookupexercise · medium · 10 min · practice plan
Report the growth of reading one array index, as constant or linear.
Passes when: #out should show constant.
6.Fix the off-by-one loop countbug fix · easy · 8 min
Using <= runs one extra iteration.
Passes when: #out should show five steps.
7.Fix the nested countbug fix · easy · 8 min · practice plan
The counter sits outside the inner loop, so it counts rows not cells.
Passes when: #out should show nine steps.
8.Fix the halving loopbug fix · medium · 8 min · practice plan
Subtracting one instead of halving makes the loop linear.
Passes when: #out should show logarithmic.
9.Fix the kept constantbug fix · easy · 8 min · practice plan
Big O drops constants, so 2n is still linear rather than doubled.
Passes when: #out should show linear.
10.Fix the scan called constantbug fix · easy · 8 min · practice plan
Searching every element is not a single read.
Passes when: #out should show linear.
Between them these tasks cover Counting operations, Dominant term and Nested loops.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.