Find the two indices in a sorted array summing to 10 and join them.
Acceptance criteria
- 1.#out should show 2-3.
DSA Tutorial · Two Pointers and Sliding Window
These 10 tasks go with The Two Pointer Technique 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: “Two pointers is how you get hash-map speed without hash-map memory. It only works when the input has an order you can exploit — which is why the first move is so often to sort.” .
1.Pair summing to a targetexercise · easy · 10 min
Find the two indices in a sorted array summing to 10 and join them.
Passes when: #out should show 2-3.
2.Reverse in placeexercise · easy · 10 min · practice plan
Reverse an array using two pointers and join the result.
Passes when: #out should show 3-2-1.
3.Squash duplicatesexercise · easy · 10 min · practice plan
Remove duplicates from a sorted array in place and join what remains.
Passes when: #out should show 1-2-3.
4.Move zeros to the endexercise · easy · 10 min · practice plan
Shift zeros to the back, keeping the order of the rest, then join.
Passes when: #out should show 1-3-0-0.
5.Container with most waterexercise · medium · 10 min · practice plan
Report the largest area between two lines.
Passes when: #out should show area 6.
6.Fix the pointer moved the wrong waybug fix · easy · 8 min
When the sum is too small, moving right down makes it smaller still.
Passes when: #out should show 2-3.
7.Fix the swap without a temporarybug fix · easy · 8 min · practice plan
Assigning one side first destroys the value the other side needs.
Passes when: #out should show 3-2-1.
8.Fix the dedupe reporting the wrong lengthbug fix · medium · 8 min · practice plan
Without truncating, the array still reports its original length.
Passes when: #out should show kept 3.
9.Fix the zeros never refilledbug fix · easy · 8 min · practice plan
Truncating instead of padding drops the zeros entirely.
Passes when: #out should show 1-3-0-0.
10.Fix the area using the taller linebug fix · easy · 8 min · practice plan
Water is limited by the shorter of the two lines.
Passes when: #out should show area 6.
Between them these tasks cover Both ends, Sorted input and In-place moves.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.