Neural Mastery
← Back to Practice

Longest Run of Unique Characters

Difficulty: Medium · Pattern: Sliding Window · Concept: General Coding (DSA) — Core Patterns to Drill

Given a string s, find the length of the longest contiguous substring that contains no repeated characters.

Checking every substring is O(n3)O(n^3) (or O(n2)O(n^2) with a smarter check). The sliding window pattern does it in one pass: grow a window from the right, and whenever a repeat shows up, shrink from the left just enough to remove it — never restart from scratch.

Your task: implement longest_unique_run(s), returning an integer length (0 for an empty string).

Implement it yourself
assert longest_unique_run("abcabcbb") == 3 assert longest_unique_run("bbbbb") == 1 assert longest_unique_run("pwwkew") == 3 assert longest_unique_run("") == 0 assert longest_unique_run("dvdf") == 3

Next: Minimum Window Substring (a harder variant), or continue to Find the Rotation Point

Last updated Sep 5, 2026Edit this pageReport an issue