Algorithmic patterns · 7 / 15 Exercise Hard

Longest substring without repeats

Objective

With a variable-size window you extend it on the right and shrink it on the left when a repeated character appears. A dictionary with the last position of each character avoids going back.

Instructions

  • Read a line of text (no spaces, not empty).
  • Show Length: n with the length of the longest contiguous substring that has no repeated characters.
Input
abcabcbb
Output
Length: 3

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise