Skip to content
RED SAGSkills

Longest Substring With Distinct Characters

Given a string s, return the length of the longest contiguous substring in which no character appears more than once.

Example 1

Input: s = "abcabcbb"
Output: 3
Explanation: "abc" is the longest such substring.

Example 2

Input: s = "pwwkew"
Output: 3
Explanation: "wke".

Constraints

  • 0 <= s.length <= 5 * 10^4
  • s may contain letters, digits, symbols and spaces.
Hint 1

Maintain a window [start, i] with no repeats.

Hint 2

Remember the last index of each character so you can jump start past a repeat.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer

Run checks your code on 2 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.