Report how many extra arrays a copying reverse allocates, as the word one or none.
Acceptance criteria
- 1.#out should show one.
DSA Tutorial · Big O and Complexity
These 10 tasks go with the Time vs Space Complexity 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: “Almost every optimisation in this tutorial is the same move: use more memory so you do less work. Knowing what you are spending is how you tell a good trade from a bad one.” .
1.Measure extra spaceexercise · easy · 10 min
Report how many extra arrays a copying reverse allocates, as the word one or none.
Passes when: #out should show one.
2.Reverse in placeexercise · easy · 10 min · practice plan
Reverse an array without allocating another one and show the result joined.
Passes when: #out should show 3-2-1.
3.Trade space for speedexercise · easy · 10 min · practice plan
Use a Set to test membership and report hit or miss.
Passes when: #out should show hit.
4.Count recursion depthexercise · easy · 10 min · practice plan
Report the depth reached by a recursion over four items.
Passes when: #out should show depth four.
5.Ignore the input sizeexercise · medium · 10 min · practice plan
An in-place sort allocates nothing — report its extra space as constant or linear.
Passes when: #out should show constant.
6.Fix the reverse that copiesbug fix · easy · 8 min
Spreading allocates a second array, so the work is no longer in place.
Passes when: #out should show 3-2-1.
7.Fix the swap losing a valuebug fix · easy · 8 min · practice plan
Assigning directly overwrites one element before it is saved.
Passes when: #out should show 9-8-7.
8.Fix counting the input as extra spacebug fix · medium · 8 min · practice plan
The input array is not extra space, so this reports the wrong class.
Passes when: #out should show constant.
9.Fix the depth counterbug fix · easy · 8 min · practice plan
Resetting the depth on each call means it never grows.
Passes when: #out should show depth four.
10.Fix the array used for membershipbug fix · easy · 8 min · practice plan
indexOf scans every element, which is the cost the Set was meant to avoid.
Passes when: #out should show hit.
Between them these tasks cover Extra space, Trade-offs and In-place work.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.