Practice Problem

Longest Substring Without Repeating Characters

Difficulty: Medium

Find the length of the longest substring without repeating characters using the sliding window technique.

Longest Substring Without Repeating Characters

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

A substring is a contiguous sequence of characters within the string.

Examples

Example 1:

Input: s = "abcabcbb"
Output: 3
Explanation: The longest substring without repeating characters is "abc", with length 3.

Example 2:

Input: s = "bbbbb"
Output: 1
Explanation: The longest substring is "b", with length 1.

Example 3:

Input: s = "pwwkew"
Output: 3
Explanation: The longest substring is "wke", with length 3.
Note that "pwke" is a subsequence, not a substring.

Example 4:

Input: s = ""
Output: 0

Constraints

  • 0 <= s.length <= 5 * 10^4
  • s consists of English letters, digits, symbols, and spaces.

Expected Complexity

  • Time: O(n)
  • Space: O(min(m, n)) where m is the charset size
MEDIUM
Strings
Sliding Window
Hash Map / Dictionary
Intermediate

0 views

Solution

Hints

Hint 1
Hint 2
Premium
Hint 3
Premium
Hint 4
Premium