FastPrepReformat an Ordinal Date
Problems/Reformat an Ordinal Date

Reformat an Ordinal Date

Expedia logoExpedia● EasyNEW GRADINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reports of this Expedia online test describe turning a written date such as 23rd Apr 2012 into 2012-04-23.

One report put the year last instead. Its only example uses the same number for day and month, so it does not show which comes first. The editorial reads it as day first (DD-MM-YYYY), and that order is our choice. Two others link a version that allows years from 1000 to 2021. The editorial covers both, but they are not tested here. The tested version keeps YYYY-MM-DD output and years 1900 to 2099. We chose the English month abbreviations and the rules for valid input.

Our version is about 90% the same as the reported questions.

Convert the valid English date date to YYYY-MM-DD.

The input has three parts separated by one space: an ordinal day such as 1st or 23rd, a three-letter month, and a four-digit year. Remove the day suffix, replace the month with its number, and use two digits for the month and day.

For example, 23rd Apr 2012 becomes 2012-04-23. Return the formatted string.

Function

reformatDate(date: String) → String

Examples

Example 1

date = "23rd Apr 2012"return = "2012-04-23"

The year is 2012, Apr is month 04, and the day is 23.

Example 2

date = "1st Jan 1900"return = "1900-01-01"

Remove st and pad both the first month and the first day to two digits.

Example 3

date = "29th Feb 2000"return = "2000-02-29"

The valid leap-day input keeps day 29 and maps Feb to 02.

Constraints

  • 12 <= date.length <= 13.
  • The input is a valid Gregorian date from 1900 through 2099. Its month is one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec. Its day has the usual English ordinal suffix and no leading zero, and its three parts are separated by one space.

More Expedia Online Assessment questions

  • Balanced NumbersOA · Seen Aug 2026
  • REST API: Discounted PriceOA · Seen Aug 2026
  • Maximum Team SizeOA · Seen Mar 2026
  • Per-Domain Request LimiterOA · Seen Oct 2025
  • Count Equal-Frequency SubsequencesOA · Seen Mar 2025
  • Count Increasing Stock PeriodsOA · Seen Mar 2025
  • Get Minimum StepsOA · Seen Oct 2024
  • Rank Songs by PopularityOA · Seen Oct 2024
  • Calculate the SumOA · Seen Oct 2024
  • Get Maximum EfficiencyOA · Seen Oct 2024

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
  • Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
  • Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
  • Branch with the Most FilesCapital One · OACapital One interview questions

Interview reports that mention this question

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia New Grad SDE Earlier Loops: 5 Experiences (Part 2 of 3)

Expedia interview experiences

  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public String reformatDate(String date) {
        // Write your code here.
    }

}
Checking account…