Skip to content
Preptima

Two Pointers & Sliding Window interview questions

Linear-time techniques for subarray and pair-finding problems that naively look quadratic.

4 questions in Data Structures & Algorithms.

medium4

mediumCoding

Find the length of the longest substring without repeating characters.

Maintain a sliding window with a map from character to its last seen index; when a duplicate appears inside the current window, jump the left boundary past that previous occurrence rather than shrinking one step at a time, giving a single-pass O(n) solution. It also connects two pointers to the point an interviewer is testing.

2 minentry, mid, senior
mediumCoding

Return every distinct triplet in the array that sums to zero.

Sort the array, fix each element as an anchor, then converge two pointers inwards from both ends of the remaining range. The sort is asymptotically free against the O of n squared scan, and it is what lets you skip duplicate values positionally instead of deduplicating a set of results afterwards. It also connects sorting to the point an interviewer is testing.

4 minentry, mid, senior