Flag Duplicate Orders Placed Within K Positions of Each Other

Last updated: November 29, 2026

Quick Overview

Given a list of order fingerprints in arrival order and an integer k, return True if any fingerprint appears twice at positions i and j with |i - j| <= k, signalling a likely accidental double order.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of order fingerprints in arrival order and an integer k, return True if any fingerprint appears twice at positions i and j with |i - j| <= k, signalling a likely accidental double order.

An Amazon phone-screen warm-up tied to duplicate-order protection at checkout. The interviewer wants a hash map of last-seen positions or a bounded sliding set, and checks whether you keep memory proportional to k rather than to the whole stream.

What the Interviewer Expects
  • Clarify whether k = 0 is allowed and what it means
  • Track the last index of each fingerprint in a dictionary
  • Offer a sliding-window set of size k to bound memory
  • Return as soon as a match is found
  • Test boundaries where the gap is exactly k and k + 1
Key Topics to Cover
Hash Set
Sliding Window
Deduplication
Arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you report every duplicate pair rather than just True or False?
  • If duplicates are defined by time (within 60 seconds) instead of position, what changes?
  • How would this run across many checkout hosts that each see part of the stream?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list orders of hashable fingerprints and integer k >= 0. Output: True if two equal fingerprints sit at distance at most k, else False. With k = 0 no pair can qualify because i and j must di...

High-Level Design

Keep a set holding the fingerprints of the last k orders. For each new order, if it is already in the set we have a duplicate within distance k. Otherwise add it, and once the set holds more than k it...


Submit Your Answer
Markdown supported