Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Length of the longest substring

Medium Acceptance 50.00% Points 30.00

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".

Hints
Hint 1
NA
Constraints
  • 1 = s.size() = 10^5
  • It is guaranteed that all characters of the String s will be lowercase letters from 'a' to 'z'
Companies
Amazon Microsoft Google Morgan Stanly
Topics
String
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions