
In Meta Messenger, you are given a message string s. Return the length of the longest contiguous substring that contains no repeated characters.
This is a standard string and sliding-window problem: scan the string once and maintain the largest valid window with all unique characters.
ss with all distinct charactersExample 1
s = "abcabcbb"3"abc", which has length 3.Example 2
s = "bbbbb"11 repeats the character "b".Example 3
s = "pwwkew"3"wke". "pwke" is not valid because a substring must be contiguous.0 <= len(s) <= 5 * 10^4s contains English letters, digits, symbols, and spacess = "abcabcbb"Output3WhyThe longest substring without repeated characters is "abc".s = "bbbbb"Output1WhyOnly one unique character can appear in any valid substring.s = "pwwkew"Output3Why"wke" is a longest valid contiguous substring.0 <= len(s) <= 5 * 10^4s consists of English letters, digits, symbols, and spacesA linear-time solution is expecteddef length_of_longest_substring(s):