Longest Substring Without Repeating Characters
Updated
Problem statement
Given a string s, return the length of the longest substring of s in which no character appears more than once.
A substring is a run of characters that sit next to each other in s. Upper and lower case letters are different characters, and a space is a character too.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "tree house"return = 6The substring " house" (a space followed by house) has 6 different characters. Any substring of length 7 repeats a character: for example "e house" has e twice.
Example 2
s = "noon"return = 2"no" and "on" both have length 2. Every longer substring has two os or two ns.
Example 3
s = "zzzz"return = 1Every substring longer than one character has two zs, so the answer is 1.
Constraints
0 <= s.length <= 5 * 10^4sconsists of English letters, digits, spaces and the characters. , ! ? -
More Bank of America Onsite Interview questions
- Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
- Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
- N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
- Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
- Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
- Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
- Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
- Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
- Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
- Second Largest Element in an ArrayONSITE INTERVIEW · Seen Jun 2023
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
- Sliding-Window Rate LimiterStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions