FastPrepClosest Version Date
Problems/Closest Version Date

Closest Version Date

Amazon logoAmazon● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a target date and a list of release dates for different software versions. Return the release date that is closest to the target date. The distance between two dates is the absolute number of calendar days between them.

If two release dates are equally close to the target date, return the later date. All dates are provided in YYYY-MM-DD format.

Function Signature

function findClosestVersionDate(targetDate: string, versions: string[]): string

Function

findClosestVersionDate(targetDate: String, versions: String[]) → String

Examples

Example 1

targetDate = "2026-04-01"versions = ["2023-04-01", "2025-04-01", "2026-05-03"]return = "2026-05-03"

2023-04-01 is 1096 days away, 2025-04-01 is 365 days away, and 2026-05-03 is 32 days away. The closest release date is 2026-05-03.

Example 2

targetDate = "2024-06-10"versions = ["2024-06-01", "2024-06-20", "2024-07-01"]return = "2024-06-01"

The first release date, 2024-06-01, is 9 days from the target date. Both later dates, 2024-06-20 and 2024-07-01, are farther away. So the answer is the first release date.

Example 3

targetDate = "2025-01-15"versions = ["2025-01-10", "2025-01-20"]return = "2025-01-20"

Both release dates are 5 days from the target date. On a tie you return the later date, so the answer is the second date in the list.

Example 4

targetDate = "2026-04-01"versions = ["2026-04-01", "2026-05-03", "2025-12-31"]return = "2026-04-01"

The first release date is the same day as the target date. An exact match has distance 0, so it is the closest release date and the answer.

Constraints

  • 1 <= versions.length <= 100000
  • targetDate and every date in versions are valid dates in YYYY-MM-DD format.
  • versions may not be sorted.
  • Follow-up
  • If versions is already sorted, can you solve each query faster than checking every date? What if there are many target dates queried against the same version list?

More Amazon Onsite Interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
  • Search a Sorted Array of WordsExpedia · ONSITE INTERVIEWExpedia interview questions
  • Lexicographic Search SuggestionsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Find the First Matching Ordered EntryFigma · OAFigma interview questions
  • Product Record SearchWells Fargo · OAWells Fargo interview questions
  • Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions
  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Roll a Weighted DieLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions

Interview reports that mention this question

  • Amazon SDE II OA and Interviews: 10 Experiences (Part 1 of 2)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public String findClosestVersionDate(String targetDate, String[] versions) {
      // write your code here
    }
}
Checking account…