ExamAdda Logo

Longest Substring Without Repeating Characters

Easy

Given a string s, find the length of the longest substring without repeating characters.

A substring is a contiguous sequence of characters within a string.

Example 1

Input

abcabcbb

Output

3

Explanation

The longest substring without repeating characters is "abc", which has a length of 3.

Example 2

Input

bbbbb

Output

1

Explanation

The longest substring without repeating characters is "b", which has a length of 1.

Constraints

0 ≤ s.length ≤ 5 × 10⁴
s consists of English letters
digits
symbols
and spaces.

Hints:

Hint 1

Use a sliding window to maintain a substring with unique characters.

Hint 2

Store the last seen index of each character in a hash map. When a duplicate character is encountered inside the current window, move the left pointer to one position after its previous occurrence.

Author & Technical Reviewer

Chatla Jithin Sri Surya

Technically reviewed by: Chatla Jithin Sri Surya

<p>IIEST Shibpur | SDE | AI, ML &amp; Gen AI | DSA | Building Intelligent, Scalable Software</p>

Published

Oct 19, 2026

Last updated

Oct 19, 2026

Last technically reviewed

Oct 19, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output