← Programming questions
Medium / PYTHON

Longest Substring without Repeated Characters

strings · hash_maps · sliding_window 22 minute study target

Not completed

Challenge

Return the length of the longest contiguous substring containing no repeated character. Characters are case-sensitive; spaces and punctuation count like letters. Return only the length.

Input and output contract

0 ≤ length ≤ 60,000. Characters are printable ASCII (codes 32–126). Empty input returns 0.

All tests follow this contract. You do not need to validate malformed input. Return the requested result from longest_unique_substring; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.

Target complexity: O(n) expected time; O(a) auxiliary space for alphabet size a

Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.

Public examples

Example 1

Arguments

['abba']

Expected return

2
Example 2

Arguments

['abcabcbb']

Expected return

3
Example 3

Arguments

['a A']

Expected return

3
Hint

Track each character’s last position. When it repeats inside your window, move the left edge forward, never backward.

The worked solution unlocks after completion, or with Premium access.

longest_unique_substring.pyPython 3.12

Drafts are saved to your account, not to shared browser storage.

Sign in to submit code and save progress.

Results

Your results will appear here.

Hidden tests reveal only their pass/fail status, never their inputs or expected outputs. Runtime is observed wall time—not an inferred complexity class.

© 2026 EverythingQuant. All Rights Reserved.