Files

19 lines
805 B
Plaintext

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)