Find the Closest Version by Date
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: Practice a Amazon coding interview problem focused on find the closest version by date. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.
Examples
Input: {"target_date":"2026-04-01","versions":[["v1","2023-04-01"],["v2","2025-04-01"],["v3","2026-05-03"]]}
Expected Output: "v3"
Explanation: Closest date.
Input: {"target_date":"2024-01-10","versions":[["a","2024-01-01"],["b","2024-01-19"]]}
Expected Output: "a"
Explanation: Tie chooses earlier date.
Input: {"target_date":"2024-01-10","versions":[["a","2024-01-10"]]}
Expected Output: "a"
Explanation: Exact match.
Input: {"target_date":"2024-01-10","versions":[]}
Expected Output: ""
Explanation: No versions.
Input: {"target_date":"2024-02-29","versions":[["leap","2024-02-29"],["next","2024-03-01"]]}
Expected Output: "leap"
Explanation: Leap date.
Input: {"target_date":"2024-01-10","versions":[["future","2025-01-10"],["past","2023-01-10"]]}
Expected Output: "past"
Explanation: Tie by earlier date.
Input: {"target_date":"2024-06-15","versions":[["x","2024-06-20"],["y","2024-06-16"]]}
Expected Output: "y"
Explanation: Near future.
Input: {"target_date":"2024-06-15","versions":[["x","2024-06-01"],["y","2024-06-10"]]}
Expected Output: "y"
Explanation: Near past.