← Whiteboard questions

Longest substring without repeating characters

DSA, Medium

Which structure or algorithm, and what does it cost.

You get a string s. A substring is a run of consecutive characters. Return the length of the longest substring in which no character appears twice. Return 0 for an empty string.

Examples

Input "abcabcbb"
Output 3
Why for "abc".
Input "bbbbb"
Output 1
Why because every character repeats.
Input "abba"
Output 2
Why for "ab" or "ba". The second a must not pull the window start back to before the second b.

Constraints

Your answer must contain

Longest substring without repeating characters · OpsKarma