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 neighboring characters, so the characters must be next to each other in s. Uppercase and lowercase letters are different characters, and a space is a character too.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "abcbdea"return = 5The substring "cbdea", from index 2 to index 6, has 5 different characters. Any longer substring would include both bs or both as.
Example 2
s = "abba"return = 2The longest substrings with no repeat are "ab" and "ba", each of length 2. The middle "bb" has a repeat, and so does the whole string.
Example 3
s = ""return = 0The string is empty, so the longest substring has length 0.
Constraints
0 <= s.length <= 5 * 10^4sconsists of English letters, digits, symbols and spaces (printable ASCII characters).
More Angel One Phone Screen questions
Similar questions at other companies
- Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions
- Longest Substring Without Repeating CharactersIBM · PHONE SCREENIBM interview questions
- Longest Substring Without Repeating CharactersTikTok · PHONE SCREENTikTok interview questions
- Find Word-Multiset WindowsAmazon · PHONE SCREEN
- Find the First Contiguous HaikuFaire · PHONE SCREEN
- Longest Substring Without Repeating CharactersCapgemini · PHONE SCREENCapgemini interview questions
- Longest Substring Without Repeating CharactersWex · PHONE SCREEN
- Minimum Window of Required WordsSalesforce · PHONE SCREENSalesforce interview questions
- Longest Substring Without Repeating CharactersRedNote · PHONE SCREEN
- Longest Substring Without Repeating CharactersNetflix · PHONE SCREENNetflix interview questions