Reformat an Ordinal Date
Updated
Problem statement
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) → StringExamples
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