← All problems

Longest Substring Without Repeating Characters

Medium stringssliding-windowhash maps LeetCode ↗
Length of the longest substring with all distinct characters.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(min(n, alphabet))

Common pitfalls

  • Moving left to last_seen+1 without max() (moves backward)
  • O(n^2) re-scanning

Your solution

Log in to save your code and track progress.