core practice · coding problem
Longest Substring Without Repeating Characters
LeetCode #3 — Longest Substring Without Repeating Characters. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/longest-substring-without-repeating-characters/
The mechanism
A sliding window maintains a contiguous range and an aggregate (sum, count, max) as it moves. Expand the right edge to include elements; shrink the left edge when a constraint breaks. Each element enters and leaves the window at most once — O(n).
Expected evidence
Pass all LeetCode test cases for this problem.
Try this drill in the practice workspace →
Hints when you need them
- Pattern hint: sliding window.
- Start with brute force, then optimize time/space.
- Write down invariants before coding.
Watch for these mistakes
- Recomputing the aggregate from scratch instead of updating incrementally
- Shrinking with an `if` when a `while` is needed to restore the invariant
- Confusing fixed-size and variable-size window templates