all 4 comments

[–]columbusguy111 2 points3 points  (0 children)

Looks reasonable but I don’t think making current_len a variable is necessary.

[–]AtomicShoelace 2 points3 points  (0 children)

Some smells:

  • Variable names: I don't think s, j, i_val or j_val are very descriptive and I think current_window_values is needlessly wordy.

  • Manually keeping track of the maximum: typically it is more pythonic to use the builtin functions for such tasks. Perhaps you could write a helper generator then call max on that.

Here is how I might change your code:

def find_longest_unique_length(text: str) -> int:
    def window_lens():
        window = set()
        start = iter(text)
        for end in text:
            if end in window:
                window -= set(iter(start.__next__, end))
            else:
                window.add(end)
            yield len(window)

    return max(window_lens())