#C10186. Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
You are given a string s
. Your task is to determine the length of the longest substring in s
that contains no repeated characters.
For example, given s = "abcabcbb"
, the answer is 3
, corresponding to the substring "abc". Similarly, for s = "pwwkew"
, the answer is 3
(with one possible answer being "wke").
The solution is based on the sliding window technique. In mathematical terms, if we denote the substring from index i to index j (inclusive) as \(s[i \ldots j]\), then the task is to find the maximum \(j-i+1\) such that the function \[ f(i,j)=\begin{cases}1 & \text{if all characters in } s[i \ldots j] \text{ are unique}\\0 & \text{otherwise} \end{cases} \] returns \(1\).
Good luck!
inputFormat
The input consists of a single line containing the string s
. The string may contain letters, digits, and other characters.
outputFormat
Output a single integer, which is the length of the longest substring without repeating characters.
## sampleabcabcbb
3