Given a string s, find the length of the longest substring without duplicate characters.
Explanation: The answer is "abc", with the length of 3.
Explanation: The answer is "b", with the length of 1.
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
s consists of English letters, digits, symbols and spaces.The most straightforward way to solve this problem is by checking each possible substring to see if it contains all unique characters. We can iterate over all possible starting points and ending points for substrings and check for uniqueness.
To reduce the complexity, we can use a sliding window technique. Instead of checking every substring, we can maintain a window and move it to the right while ensuring all characters within the window are unique.
Further optimization can be done by optimizing the move of the start pointer. We can use a hash map to track the last seen index of each character, which allows skipping over sections of the string already known to contain non-unique characters.