Longest Substring Without Repeating Characters
Problem statement
Given a string s, return the length of its longest contiguous substring that contains no repeated characters.
Interview follow-up
The report also describes allowing k repeats, without defining what counts as a repeat. For this exercise, assume the discussion variant counts total excess occurrences: sum(max(0,count[c]-1)) <= k. Explain how to maintain that budget in a sliding window. This variant is discussion only; the judged function still requires no repeated character.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "abcabcbb"return = 3"abc" is a longest substring without repeated characters, so the answer is 3.
Example 2
s = "bbbbb"return = 1Every substring with distinct characters contains at most one b.
Constraints
1 <= s.length <= 10^5.scontains English letters, digits, and common symbols.