Flag Repeated Order IDs Within a Recent Message Window
Last updated: November 29, 2026
Quick Overview
Given a stream of order IDs arriving from an exchange gateway and an integer k, return every pair of positions (i, j) where the same ID appears at position i and again at a position j with i - j at most k.
SIG
November 29, 20260
0
0 solved
Given a stream of order IDs arriving from an exchange gateway and an integer k, return every pair of positions (i, j) where the same ID appears at position i and again at a position j with i - j at most k.
SIG's online assessment often opens with a short warm-up framed around trading infrastructure, such as catching duplicate or replayed order messages from a gateway. The grader checks that you reach a single-pass hash map solution and get the window boundary exactly right rather than comparing every pair.
What the Interviewer Expects
- Clarify whether the window is measured in message count or time, and whether k is inclusive
- Use a dict of last-seen index for a single O(n) pass
- Report the most recent previous occurrence, not the first one
- Handle empty input and k = 0 cleanly
- Explain why keeping only the last index is enough
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you change this if the window were 50 milliseconds instead of k messages?
- What if memory is bounded and the ID space is huge?
- How would you report only the first duplicate per ID per trading session?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a list ids (strings or ints) in arrival order and an integer k >= 0. Output: a list of (i, j) where ids[i] == ids[j], j < i, and i - j <= k, with j the most recent earlier positio...
High-Level Design
Brute force compares each message with the previous k, which is O(nk). Instead keep last[id] = index of most recent occurrence. When a message arrives, if its ID is in last and the gap is within k...