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 are next to each other in s. Uppercase and lowercase letters are different characters, and a space is a character too. If s is empty, return 0.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "pqrpqrqq"return = 3The substring "pqr" has three different characters. Any substring of length 4 repeats a character; for example "pqrp" has p twice. So the answer is 3.
Example 2
s = "aaaa"return = 1Every substring longer than one character repeats a, so the answer is 1.
Example 3
s = "dvdf"return = 3The substring "vdf" has three different characters, and the whole string repeats d, so the answer is 3. Note that the best substring starts at the v, not at the second d.
Constraints
0 <= s.length <= 5 * 10^4sconsists of English letters, digits, symbols and spaces (printable ASCII characters).
More Oracle Onsite Interview questions
- Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
- Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
- Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
- Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
- Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
- Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
- Maximum Bouquet ValueONSITE INTERVIEW · Seen Oct 2026
- Cache an Expensive Service Across ThreadsONSITE INTERVIEW · Seen Oct 2026
- Island Count and Maximum AreaONSITE INTERVIEW · Seen Oct 2026
- Largest Island After One FlipONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- 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
- Longest Substring Without Repeated CharactersDatadog · ONSITE INTERVIEWDatadog interview questions