Longest Substring Without Repeating Characters
Given a string `s`, find the length of the longest substring without duplicate characters. **Examples:** ```typescript lengthOfLongestSubstring("abcabcbb") // 3 ("abc") lengthOfLongestSubstring("bbbbb") // 1 ("b") lengthOfLongestSubstring("pwwkew") // 3 ("wke") ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(n)
- Space complexity: O(min(m, n))
Sliding window right pointer advances n times, moving left pointer in O(1) jumps.
Follow-Up Questions Interviewers Ask About Longest Substring Without Repeating Characters
- Why store character indices rather than just a boolean set?
Storing indices allows the left window boundary to jump directly past the last occurrence of the duplicate character in O(1).
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.