2dbi

Longest substring without repeating characters

via2dbi

Problem

Find the length of the longest substring without repeating characters.

Example

"abcabcbb" -> 3   ("abc")

Constraints

  • Aim for O(n) time

Approach

Sliding window with a last-seen index map; advance the left edge past any repeat.

Add a follow-up question they asked
Return the substring itself
Generalize to at most k distinct
asked …
LeaderboardSalary
Language
Account