Longest Substring Without Repeated Characters
Problem statement
Given a string s, return the largest length of a contiguous substring in which every character is different.
A substring uses consecutive positions. Spaces, punctuation, digits, uppercase letters, and lowercase letters count as distinct characters. The empty string has answer zero.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "abcaef"return = 5The substring bcaef has five different characters. A longer substring would be the whole six-character string, which repeats a. Return 5.
Example 2
s = "cccc"return = 1Every substring of length two or more repeats c. A one-character substring is valid, so return 1.
Constraints
0 <= s.length <= 2000- Every character is printable ASCII, with a code from 32 through 126.