Variable window: longest unique substring

Step 2: Variable window: longest unique substring

Log and text analysis frequently needs the longest run with no repeats. Here the window grows and shrinks. Keep a last-seen map from character to its most recent index, and a start pointer for the window left edge. When you meet a character already seen at or after start, jump start to just past that previous position.

Implement longest_unique(s) returning the length of the longest substring of s that contains no repeating characters.

Example: longest_unique("abcabcbb") is 3, from "abc".

Hints
Starter code
def max_sum_window(nums, k):
    if k <= 0 or k > len(nums):
        return None
    window = sum(nums[:k])
    best = window
    for i in range(k, len(nums)):
        window += nums[i] - nums[i - k]
        if window > best:
            best = window
    return best


def longest_unique(s):
    # TODO: return the length of the longest substring without repeating characters.
    # Keep a last-seen index map and a window start pointer.
    # When a repeat is found at or after start, move start past its previous index.
    pass
Write it on a laptop

The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.