Longest Substring Without Repeating Characters

Medium

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

Example 1

lengthOfLongestSubstring()
Input
s = "abcabcbb"
Output
3

Why

The answer is "abc", with the length of 3.

Example 2

lengthOfLongestSubstring()
Input
s = "bbbbb"
Output
1

Why

The answer is "b", with the length of 1.

Example 3

lengthOfLongestSubstring()
Input
s = "pwwkew"
Output
3

Why

The answer is "wke", with the length of 3.
Constraints
0 <= s.length <= 5 * 10^4
s consists of English letters, digits, symbols and spaces.

Topics

StringsSliding WindowHash Table

Implement lengthOfLongestSubstring in the editor and return the answer — printing it is never graded.