Skip to main content
Data Structures & Algorithms·Longest Substring Without Repeating Characters
Medium72% accepted

Longest Substring Without Repeating Characters

Sliding WindowHash SetString
Problem Statement

Given a string s, find the length of the longest substring without repeating characters. Use the sliding window technique to efficiently track unique characters.

Examplespublic test cases
  • "abcabcbb" → 3 (abc)

    Input length_of_longest_substring("abcabcbb")

    Output 3

  • "bbbbb" → 1 (b)

    Input length_of_longest_substring("bbbbb")

    Output 1

  • "pwwkew" → 3 (wke)

    Input length_of_longest_substring("pwwkew")

    Output 3

  • Empty string → 0

    Input length_of_longest_substring("")

    Output 0

Complexity
TimeO(n)
SpaceO(min(m, n))
Asked By
AmazonBloombergMicrosoft

Ready to solve?

Open the code editor with the official template, run tests, and iterate.