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
Returns (int) 3

Example 2

Input
s (string) = bbbbb
Returns (int) 1

Example 3

Input
s (string) = pwwkew
Returns (int) 3

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

Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.