Walk the array once and show the largest value found.
Acceptance criteria
- 1.#out should show nine.
DSA Tutorial · Arrays
These 10 tasks go with the Array Traversal Patterns 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: “Most array problems are one of four walks. Recognising which one you need is faster than inventing a solution from scratch.” .
1.Track a running maximumexercise · easy · 10 min
Walk the array once and show the largest value found.
Passes when: #out should show nine.
2.Sum in one passexercise · easy · 10 min · practice plan
Add every value and show the total.
Passes when: #out should show total 12.
3.Remove zeros in placeexercise · easy · 10 min · practice plan
Use read and write pointers to strip zeros, then join what remains.
Passes when: #out should show 1-3.
4.Walk from both endsexercise · easy · 10 min · practice plan
Report whether the array reads the same forwards and backwards.
Passes when: #out should show mirrored.
5.Remember what you sawexercise · medium · 10 min · practice plan
Use a Set to report the first value that repeats.
Passes when: #out should show repeat is 2.
6.Fix the maximum seeded with zerobug fix · easy · 8 min
Starting at zero breaks when every value is negative.
Passes when: #out should show minus two.
7.Fix the write pointer never advancingbug fix · easy · 8 min · practice plan
Without incrementing write, every kept value lands in slot zero.
Passes when: #out should show 1-3.
8.Fix the pointers moving the same waybug fix · medium · 8 min · practice plan
Both pointers advance forwards, so every element is only ever compared with itself.
Passes when: #out should show different.
9.Fix the Set checked after addingbug fix · easy · 8 min · practice plan
Adding before testing means every value looks like a repeat.
Passes when: #out should show repeat is 2.
10.Fix removal while looping forwardsbug fix · easy · 8 min · practice plan
Splicing during a forward loop skips the element that shifts into place.
Passes when: #out should show 1-3.
Between them these tasks cover Running state, Read and write pointers and Both ends.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.