← DiffPush

Longest Substring Without Repeating Characters

Standard Bar Sliding Window · Medium Problems O(n) · O(m)

The Radio Call-Sign Scanner

An aviation radio logs a continuous stream of call-sign characters, and the tower software highlights the longest stretch in which no character appears twice — such stretches can be bundled into a single transmission packet without ambiguity. The scanner slides a frame over the log, retreating its left edge just far enough whenever a duplicate sneaks in, and reports the widest clean frame it ever saw.

Input: A string s of characters.

Output: Return the length of the longest substring in which every character occurs exactly once.

Constraints

Examples

Example 1

Input: {"s":"abcabcbb"}
Output: 3
The cleanest stretch is "abc"; the fourth character repeats and forces a retreat.

Example 2

Input: {"s":"bbbbb"}
Output: 1
Every pair repeats, so a single character is the widest unique frame.

Solve this in your browser →

Also on LeetCode ↗