cheetcode

16. Longest Substring Without Repeating CharactersMedium

Find the longest substring length without duplicate characters.

Given a string s, find the length of the longest substring without repeating characters.

Maintain only the current window state as it expands or shrinks. Watch for the exact condition that makes a window valid, invalid, or worth recording.

Examples

Input: s = "abcabcbb"
Output: 3
Explanation: The answer is abc.
Input: s = "bbbbb"
Output: 1
Explanation: The answer is b.
Input: s = ""
Output: 0

Constraints

  • 0 <= s.length <= 50,000
  • s may contain letters, digits, symbols, and spaces.