Reformat Date

EasyStringssimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given a date string in the form "Day Month Year": - Day is one of "1st", "2nd", "3rd", "4th", ..., "30th", "31st" (standard English ordinal suffixes). - Month is a three-letter abbreviation: "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec". - Year is a four-digit year. Return the same date as "YYYY-MM-DD", zero-padding the month and day to two digits. The input is always a valid calendar date.

Examples

Input: date = "20th Oct 2052"
Output: "2052-10-20"
October is month 10 and the day is 20.
Input: date = "6th Jun 1933"
Output: "1933-06-06"
Both month and day need a leading zero.
Input: date = "1st Jan 2000"
Output: "2000-01-01"
The "st" suffix is dropped and 1 is padded to 01.

Constraints

  • The year is in the range [1900, 2100]
  • The date is always valid
  • `date` uses single spaces between its three parts

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems