Build sliding window and two pointer skills through array and string questions involving ranges, frequencies and movement rules.
Log in/Sign up to track your progress
Striver’s Sliding Window and Two Pointers Sheet contains 22 coding questions. It retains every practice question from the corresponding A2Z section and includes additional applications from existing TUF sheets. A linked pattern-and-template lesson introduces the reasoning before the coding list.
Striver’s Sliding Window and Two Pointer Sheet includes 22 problems spanning sorted scans, in-place compaction, fixed windows, longest valid ranges, exact counts and minimum matching windows. Some questions combine boundary movement with frequency maps or a monotonic deque. The aim is to choose a movement rule from the constraints instead of applying one window template to every task.
Keep the output requirement visible throughout your attempt. Finding one valid range, finding the longest range and counting all valid ranges need different bookkeeping. Likewise, matching characters in any order is different from finding an ordered subsequence. A small trace should show both the boundary movement and how the requested answer changes.
Two-pointer questions use positions that may move toward one another or in the same direction. Window questions maintain information about a contiguous range, such as its total, frequencies or validity. Different outputs require different bookkeeping: one valid range, a longest range and a count of ranges are not interchangeable tasks.
The existing theory lesson covers the pattern and its template. Know array and string positions, loops and basic frequency counting first. Also distinguish sorted inputs, nonnegative values and arbitrary signed values, because the same movement rule is not valid under all three conditions.
Be comfortable with zero-based positions, inclusive and exclusive boundaries, frequency maps and contiguous subarrays or substrings. A subsequence can skip positions; a window cannot. Know whether sorting is allowed, since rearranging the input can destroy the original contiguous ranges or the index information a task needs.
Before shrinking a window, explain why that movement is safe. A positive-sum rule does not automatically extend to inputs containing negative values. With values four and negative one and a target of three, discarding the first value as soon as the sum exceeds three would lose a valid range. The input restrictions are part of the algorithm.