Eyes only
Given a string s, return the length of the longest contiguous substring in which every character is unique.
0 ≤ len(s) ≤ 50,000s may contain letters, digits, symbols and spaces.RecThis meeting is being recorded.
Please analyze this context and help me answer the question or solve the problem.
"Okay, next one. Given a string, return the length of the longest substring that has no repeating characters. Walk me through your approach before you code it."
def length_of_longest_substring(s: str) -> int: last_seen = {} # char -> index left = best = 0 for right, ch in enumerate(s): if ch in last_seen and last_seen[ch] >= left: left = last_seen[ch] + 1 # jump past it last_seen[ch] = right best = max(best, right - left + 1) return best last_seen = {} # char -> indexAt each index r, the window's left edge is:
Time O(n): each character enters and leaves the window once.
Space O(min(n, k)): k is the size of the character set.