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:
@@ -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)
|
||||
Reference in New Issue
Block a user