Proficient Level

Implement the method longestUniqueSubstring that returns the length of the longest substring without repeated characters.

Find the longest contiguous substring where every character appears only once.

The task is designed to test careful handling of edge cases, not only the most common input.

  • The result is a length, not the substring text.
  • Character matching is case-sensitive.
  • Move the left side of the window past duplicates.
Example 1
Input:
s (string) = abcabcbb
Return:
(int) 3
Example 2
Input:
s (string) = bbbbb
Return:
(int) 1
Example 3
Input:
s (string) = pwwkew
Return:
(int) 3

Use a sliding window and a map of last-seen positions to keep the current window unique.

Run your code to see the result.