Two pointers interview questions
Pointers from both ends of sorted data, read and write pointers for in-place edits, and merging sorted sequences, with the reasoning that makes them correct.
– interview-ready · 12 questions in this topic
– of 12 tried
Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.
Questions
- Do two sorted prices add up to a target?Predict
- Push the empty parking slots to the endSpot the bug
- Does a banner read the same both ways?Predict
- Merge two sorted shelves into oneFill the blank
- Remove repeated readings from a sorted log in placePredict
- Count weight triples that stay under a limitPredict
- Squared deviations in sorted orderPick the fix
- Is a short route hidden inside a long one?Predict
Practise this topic
Flashcards · 22
Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.
Quick quiz · 12 questions
One exercise per question, checked as you go. Needs JavaScript.
Mock interview · 2 sets
Timed, out loud, then tick what you covered. Needs JavaScript.
Fix this PR · 2 reviews
Review a diff like a senior: flag the lines you'd comment on. Needs JavaScript.
Quick facts
Recall the answer first, then tap Show to check.
sorted()vslist.sort()sorted()returns a new list;list.sort()sorts in place and returns None. Both are stable and O(n log n).Python sort algorithm
CPython sorts with Timsort (Powersort's merge policy since 3.11): stable, O(n log n) worst case, and close to O(n) on input that is already mostly in order.
Swapping in Python
a[i], a[j] = a[j], a[i]swaps without a temporary variable; the right side is evaluated first.Kotlin
MutableListswapjava.util.Collections.swap(list, i, j)swaps two positions; on an IntArray you swap with a temporary or.also.Slicing copies
a[i:j]builds a new list of j - i items, so slicing inside a loop adds O(k) per slice.
Printable cheat sheet · Review your weak spots in this topic
Share your progress
Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license