Longest Substring Without Repeating Characters
Updated
Problem statement
Given a string s, return the length of its longest contiguous substring that contains no repeated characters.
Follow-up
Allow k repeats. For this discussion, count 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; your 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.
More Benchling interview questions
- Validate Nested JSON Against a SchemaONSITE INTERVIEW · Seen Dec 2025
- Degenerate DNA Substring SearchONSITE INTERVIEW · Seen Jun 2024
- Bounded HTTP Retry FlowPHONE SCREEN · Seen Nov 2025
- Future-Aware Cache EvictionPHONE SCREEN · Seen Aug 2025
- Generate All Contiguous Protein ChainsPHONE SCREEN · Seen Jul 2024
- Eight-Direction Keyboard Typing TimePHONE SCREEN · Seen Apr 2022
- Generate Proteins from Contiguous Named SequencesPHONE SCREEN · Seen Aug 2021
- Next Palindrome NumberPHONE SCREEN · Seen Jul 2021
- Apply Overlapping HTML Formatting RangesPHONE SCREEN · Seen Feb 2019
- 2048 Move SimulatorOA · Seen Feb 2019
Similar questions at other companies
- Longest Substring Without Repeating CharactersOracle · ONSITE INTERVIEWOracle interview questions
- Longest Substring Without Repeating CharactersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Longest Substring Without Repeating CharactersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Longest Substring Without Repeating CharactersGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Substring Without Repeating CharactersAmazon · ONSITE INTERVIEW
- Longest Substring Without Repeating CharactersInfosys · ONSITE INTERVIEWInfosys interview questions
- Longest Substring Without Repeating CharactersOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Longest Substring Without Repeating CharactersBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Longest Substring with At Most K Distinct CharactersGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Longest Substring Without Repeating CharactersBank of America · ONSITE INTERVIEWBank of America interview questions