Report the technique for finding a pair in a sorted array.
Acceptance criteria
- 1.#out should show two pointers.
DSA Tutorial · Interview Patterns
These 10 tasks go with the Recognising the Pattern 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: “Interviewers do not have unlimited questions. Almost everything asked is a variation on a small set of patterns, and the wording gives away which one before you have written a line.” .
1.Sorted pair sumexercise · easy · 10 min
Report the technique for finding a pair in a sorted array.
Passes when: #out should show two pointers.
2.Unsorted pair sumexercise · easy · 10 min · practice plan
Report the technique when the array is not sorted.
Passes when: #out should show hash map.
3.Longest run without repeatsexercise · easy · 10 min · practice plan
Report the technique for the longest run with no repeated value.
Passes when: #out should show sliding window.
4.Shortest path, equal weightsexercise · easy · 10 min · practice plan
Report the technique for fewest hops on an unweighted graph.
Passes when: #out should show breadth first.
5.Small n, all combinationsexercise · medium · 10 min · practice plan
Report the technique when n is at most twenty and every subset matters.
Passes when: #out should show bitmask.
6.Fix two pointers used on unsorted databug fix · easy · 8 min
Moving inward only works when the values are ordered.
Passes when: #out should show hash map.
7.Fix sorting used for a contiguous runbug fix · easy · 8 min · practice plan
Sorting destroys the order the run depends on.
Passes when: #out should show sliding window.
8.Fix Dijkstra used on equal weightsbug fix · easy · 8 min · practice plan
With every edge weighing one, a plain queue is enough.
Passes when: #out should show breadth first.
9.Fix the bitmask used for a large nbug fix · medium · 8 min · practice plan
Two to the forty is far beyond what can be enumerated.
Passes when: #out should show too many states.
10.Fix the quadratic scan on a large inputbug fix · easy · 8 min · practice plan
A hundred thousand items rules out comparing every pair.
Passes when: #out should show linear pass.
Between them these tasks cover Matching problem to technique, Reading constraints and Cost budgets.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.