Code With Wilson

LeetCode #3 — Longest Substring Without Repeating Characters, Walked Through the Six-Phase Framework

Whenever a problem asks for the longest (or shortest) **subarray or substring** with some property, the answer is **sliding window**. Two pointers — `left` and `right` — define a window over the input. The right pointer expands the window; when the property breaks, the left pointer shrinks until the property holds again. NeetCode's canonical approach uses a **hashset** to track unique characters and shrinks the window from the left until the duplicate is gone. Longest Substring Without Repeating Characters is the **canonical sliding window**. Two pointers, a hashset, one pass. The window grows from the right and shrinks from the left when the uniqueness property breaks. **O(n) time by amortization** — each character is touched at most twice. NeetCode's `while`-loop shrink is the part that makes the algorithm correct on multi-char duplicates. **The pattern transfer: any time the problem says "longest" or "shortest" plus "substring" or "subarray" with some property, reach for sliding window. The data structure tracking 'what's in the window' depends on the property.** ---