Problem · String
Longest Substring Without Repeating Characters
Learn this problemProblem statement
Given a string s, return the length of the longest contiguous substring whose characters are all distinct.
For this exercise, assume s contains printable ASCII characters. The empty string has answer 0.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "abcabcbb"return = 3The substring abc has three distinct characters. Any longer substring repeats at least one character.
Example 2
s = "pwwkew"return = 3Both wke and kew have length 3. The answer concerns a contiguous substring, not a subsequence.
Example 3
s = ""return = 0The empty string contains no non-empty substring, so its longest valid length is 0.
Constraints
0 <= s.length <= 100000scontains printable ASCII characters.
More Netflix problems
- Count String Pairs With Disjoint CharactersPHONE SCREEN · Seen Aug 2026
- Deduplicate Homepage Content Across RowsPHONE SCREEN · Seen Aug 2026
- Longest Consecutive Identical Character RunPHONE SCREEN · Seen Aug 2026
- Movie Billboard RotationONSITE INTERVIEW · Seen Jul 2026
- Topological Sort for Ads TasksPHONE SCREEN · Seen Jun 2026
- Command Undo Data StructureONSITE INTERVIEW · Seen Apr 2026
- Timed Cache with Sidecar CleanupONSITE INTERVIEW · Seen Apr 2026