1/32
Part 1 of 6 · Two pointersLearn

Windows over a request log

Netflix software engineer candidates report the longest substring without a repeated character in coding rounds (2 reports), once on an array of numbers (1 source), and it's on Netflix's LeetCode tag lists (2 sources). The practice problem sets it in an API gateway's request log:

An API gateway writes one entry per request: the key of the client that sent it, in the order the requests arrived. Keys are hashable values, strings in most tests. A run is a stretch of consecutive entries.

Write longest_distinct_run(keys) -> tuple[int, int]. keys is a list. Return (start, length) for the longest run in which no key appears twice, where start is the index of the run's first entry. When several runs tie for longest, return the one that starts first. An empty log returns (0, 0). Make it one pass: O(n) for n entries.

LogReturns
["ana", "bo", "cy", "ana", "dee", "eli", "bo", "fay"](2, 6)
["u3", "u7", "u3", "u1", "u9", "u7", "u2", "u1"](2, 5)
["u1", "u2", "u2", "u1"](0, 2), the first of two runs of 2
["ana", "ana", "ana"](0, 1)
[](0, 0)

Two more levels follow. Level 2 flags the entries whose client is also among the k requests just before, on a live stream you can read only once. Level 3 is a rate limiter: at most limit requests per client in any window seconds, with memory that holds only the requests that still count.

You don't write it yet. The lesson starts with two indexes on sorted data and builds the window one idea at a time. At the end you solve the whole problem, level by level, in an interview simulation with a 40-minute timer.

This lesson builds on hash maps: the window keeps a count of what's inside it in a dict. The same window, measured in seconds instead of positions, becomes a rate limiter here, and time windows come back in the database's level 3, in the coding builds, where small systems grow in levels.