Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Length of the longest substring

Medium Acceptance 50% Points 30

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

Examples
Example 1

Example 1

Input: s = "geeksforgeeks"

Output: 7

Explanation: Longest substring is "eksforg".

Example 2

Example 2

Input: s = "abdefgabef"

Output: 6

Explanation: Longest substring are "abdefg" , "bdefga" and "defgab".

Example 3

Example 3

Input: s = "aaaaa"

Output: 1

Explanation: Longest substring is "a".

Constraints
  • 1 = s.size() = 10^5
  • It is guaranteed that all characters of the String s will be lowercase letters from 'a' to 'z'
Topics
String
Companies
Amazon Microsoft Google Morgan Stanly
Added 18 Aug 2025 50% acceptance
Ln 1, Col 1Sign in to save your code
scholarhat
7