The Longest Journey
Start Timer
0:00:00
Given a string s, imagine reading through it one character at a time, as if you’re following a path made of letters. As you move forward, you want to keep track of the longest stretch you can travel without encountering the same character twice. String s consists of English letters, digits, symbols and spaces.
Your task is to find the length of the longest substring without duplicate characters — in other words, the longest continuous portion of s where every character is unique and no repeats interrupt the journey.
Example 1:
Input:
s = "xyzxyzyyxxxx"
Output:
def longest_substring_length(s) -> 3
Explanation: The answer is "xyz", with the length of 3. Note that "yzx" and "zxy" are also correct answers.
Example 2:
Input:
s = "xxxxxxxxxxxxxx"
Output:
def longest_substring_length(s) -> 1
Explanation: The answer is "x", with the length of 1.
Constraints:
0 <= s.length <= 5 * 10^4
.
.
.
.
.
.
.
.
.
Comments