Coding · must-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Longest Substring Without Repeating Characters
Problem
Given a string s, return the length of the longest contiguous substring in which no character appears more than once.
shas at most 60,000 characters and may be empty.- Any printable ASCII character can appear, including spaces and punctuation.
Examples
s = "xyzxyzyy"→3."xyz"(and later"zxy") is as long as a distinct run gets; the fourth character repeats the first.s = "ggggg"→1. Any two adjacent characters are equal.s = "kvvzpakl"→6."vzpakl"has six distinct characters; extending it left would add a secondv.
Hints
- If a substring is valid, every substring inside it is valid too. What does that suggest about how a window should grow and shrink?
- When the character at the right end repeats one already in the window, where must the left end move to?
- Sliding window with a map from character to its most recent index; jump the left boundary straight past the previous occurrence.
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.