Flag URL requests repeated within the last 5 time units

Quick Overview

Given a list of URL requests indexed by arrival time, label each request as error or resolved depending on whether the same URL arrived within the previous five time units. It tests single-pass array processing with fast lookups and careful handling of a strict window boundary.

Flag URL requests repeated within the last 5 time units

Company: Deliveroo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given an array of strings `urls`, where each index `i` is the **arrival time** of the URL request `urls[i]`. For each request, return `"error"` if the **same URL** appeared at a previous index within the last 5 time units, that is, `i - j < 5`, where `j` is the most recent prior occurrence of the same URL. Otherwise, return `"resolved"`. Return an array of strings where the `i`-th entry is the status of the `i`-th request. ### Function Signature ```python def track_requests(urls: list[str]) -> list[str]: ``` ### Rules - Two requests have the same URL when their strings are exactly equal. - `j` is the most recent earlier index holding the same URL, whatever status that earlier request received. A request marked `"error"` still counts as an occurrence for the requests after it. - The comparison is strict: a gap of exactly 5 (`i - j == 5`) gives `"resolved"`. - A URL with no earlier occurrence is `"resolved"`. ### Constraints - `1 <= len(urls) <= 10^5` - `1 <= len(urls[i]) <= 100` - `urls[i]` consists of printable ASCII characters. ### Examples ```text Input: urls = ["a.com","b.com","a.com","c.com","b.com","a.com"] Output: ["resolved","resolved","error","resolved","error","error"] ``` Indices 0, 1 and 3 are first occurrences. Index 2 repeats `a.com` from index 0 (gap 2), index 4 repeats `b.com` from index 1 (gap 3), and index 5 repeats `a.com` from index 2 (gap 3), so all three are errors. ```text Input: urls = ["x.io","y.io","z.io","x.io","y.io","z.io"] Output: ["resolved","resolved","resolved","error","error","error"] ``` The first three requests are first occurrences. Each of the last three repeats a URL seen 3 time units earlier, which is inside the window. ```text Input: urls = ["a.com","b.com","c.com","a.com","d.com","e.com","b.com","a.com"] Output: ["resolved","resolved","resolved","error","resolved","resolved","resolved","error"] ``` Index 6 repeats `b.com` from index 1, but the gap is exactly 5, so it is resolved. Index 3 is an error (gap 3 from index 0), and index 7 is measured against index 3, the most recent `a.com`, so its gap is 4 and it is an error too.

Overview: Given a list of URL requests indexed by arrival time, label each request as error or resolved depending on whether the same URL arrived within the previous five time units. It tests single-pass array processing with fast lookups and careful handling of a strict window boundary.

Deliveroo logo
Deliveroo
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given an array of strings urls, where each index i is the arrival time of the URL request urls[i].

For each request, return "error" if the same URL appeared at a previous index within the last 5 time units, that is, i - j < 5, where j is the most recent prior occurrence of the same URL. Otherwise, return "resolved".

Return an array of strings where the i-th entry is the status of the i-th request.

Function Signature

def track_requests(urls: list[str]) -> list[str]:

Rules

  • Two requests have the same URL when their strings are exactly equal.
  • j is the most recent earlier index holding the same URL, whatever status that earlier request received. A request marked "error" still counts as an occurrence for the requests after it.
  • The comparison is strict: a gap of exactly 5 ( i - j == 5 ) gives "resolved" .
  • A URL with no earlier occurrence is "resolved" .

Constraints

  • 1 <= len(urls) <= 10^5
  • 1 <= len(urls[i]) <= 100
  • urls[i] consists of printable ASCII characters.

Examples

Input: urls = ["a.com","b.com","a.com","c.com","b.com","a.com"]
Output: ["resolved","resolved","error","resolved","error","error"]

Indices 0, 1 and 3 are first occurrences. Index 2 repeats a.com from index 0 (gap 2), index 4 repeats b.com from index 1 (gap 3), and index 5 repeats a.com from index 2 (gap 3), so all three are errors.

Input: urls = ["x.io","y.io","z.io","x.io","y.io","z.io"]
Output: ["resolved","resolved","resolved","error","error","error"]

The first three requests are first occurrences. Each of the last three repeats a URL seen 3 time units earlier, which is inside the window.

Input: urls = ["a.com","b.com","c.com","a.com","d.com","e.com","b.com","a.com"]
Output: ["resolved","resolved","resolved","error","resolved","resolved","resolved","error"]

Index 6 repeats b.com from index 1, but the gap is exactly 5, so it is resolved. Index 3 is an error (gap 3 from index 0), and index 7 is measured against index 3, the most recent a.com, so its gap is 4 and it is an error too.