Add sliding-window module: 12 sliding window and two-pointer interview problems, brute-force cross-checks, dry-run traces, operation counts, pitfalls (11 tests)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6EqSkUWKNBc8i3Q3U
This commit is contained in:
2026-11-09 08:40:07 +00:00
co-authored by Claude Sonnet 5.5
parent 4a9021d936
commit 911aef5515
26 changed files with 1600 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
Four classic mistakes, each reproduced
======================================
1. longest substring without repeats, left = lastSeen + 1 WITHOUT Math.max
input "abba": buggy = 3 correct = 2
at the final 'a', lastSeen('a') = 0, so the buggy code moves left from 2 back to 1
2. minimum-size subarray window used on input that contains negatives
target 3, input [-2, -2, 3]: window = 0 ("none") brute force = 1 ([3])
the running sum is -1 when the 3 arrives, so the window never looks valid
3. 3Sum without skipping duplicates
input [-1, 0, 1, 2, -1, -4]
buggy = [[-1, -1, 2], [-1, 0, 1], [-1, 0, 1]]
correct = [[-1, -1, 2], [-1, 0, 1]]
4. two pointers on an array that is NOT sorted
input [3, 2, 4], target 6: twoSumSorted = [] but 2 + 4 = 6 exists (brute force: true)