Look at this Python code and tell me what it is doing.
Explain the algorithm, its output, and its complexity. Then implement an equivalent function that accepts a string and returns the length of its longest substring without repeating characters.
def analyze(text):
last_seen = {}
start = best = 0
for end, char in enumerate(text):
if char in last_seen and last_seen[char] >= start:
start = last_seen[char] + 1
last_seen[char] = end
best = max(best, end - start + 1)
return best
Input: a string. Output: an integer length. Treat every character, including spaces and symbols, as distinct.
def analyze(text):