Longest substring without repeating characters
Coding problemMediumAsked in: Coupa
Given a string s, return the length of the longest substring in which no character appears twice. A substring is a run of consecutive characters.
Upper and lower case letters are different characters. Spaces and symbols count as characters too. An empty string gives 0.
Examples
Example 1
Input: s = "abcabcbb"
Output: 3
The substring "abc" has no repeats.
Example 2
Input: s = "bbbbb"
Output: 1
Example 3
Input: s = "pwwkew"
Output: 3
The answer is "wke". The letters "pwke" do not form a substring because they are not consecutive.
Constraints
- The length of s is between 0 and 100,000
- s holds printable ASCII characters only
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.