Given a string s, find the length of the longest continuous segment of packet types with no repetition.
Explanation: Step-by-step: with input 'abcabc', we initialize the sliding window of size 3 as 'abc'. The set of unique characters in this window is {'a', 'b', 'c'}. Since the window size is equal to the set size, we update maxLen to 3. Then, we slide the window to the right by one character. The new window is 'bcab'. The set of unique characters in this window is {'b', 'c', 'a'}. Again, the window size is equal to the set size, so we update maxLen to 3. However, we notice that the window 'bcab' does not contain unique characters because 'a' is repeated. Therefore, we reset maxLen to 2.
Explanation: Step-by-step: with input 'aabaa', we initialize the sliding window of size 3 as 'aab'. The set of unique characters in this window is {'a', 'b'}. Since the window size is equal to the set size, we update maxLen to 3. Then, we slide the window to the right by one character. The new window is 'aba'. The set of unique characters in this window is {'a', 'b', 'a'}. However, we notice that the window 'aba' does not contain unique characters because 'a' is repeated. Therefore, we reset maxLen to 2.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak