All problems

Longest Substring Without Repeating Characters

hardPythonStringsSliding Window

Dunmore Rail records the platform each train uses as one character, in the order the trains arrive. Safety wants the longest clean spell: an unbroken run of arrivals during which no platform was used twice. Because the run has to be unbroken, a repeat anywhere inside it ends the spell — the characters either side cannot be stitched together across the offender.

Task: Print the length of the longest unbroken run of arrivals in which no character repeats.

Input

A single line holding between 1 and 100000 characters with no spaces. Characters may repeat, and are letters, digits or punctuation.

Output

One line holding a single integer: the number of characters in the longest unbroken run that contains no repeated character. The run must be a solid stretch of the line, so its characters sit next to each other in the input with nothing skipped.

Example:

Input:
abcabcbb

Output:
3

("abc" has length 3)

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…