
Asked in Expedia Group
Date Reformatting
You have a string 'S' representing a date in the "Day Month Year" format, where:
- Day is one of {"1st", "2nd", "3rd", ..., "29th", "30th", "31st"}.
- Month is one of {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
- Year is such as 2020, 2021, etc.
Your task is to reform this date into the "YYYY-MM-DD" format:
- YYYY is a 4 digit year.
- MM is a 2 digit month.
- DD is a 2 digit day.
Input:
The first line contains an integer ‘T’, the number of test cases.
Each test case has a single string ‘S’ representing the date.
Output:
For each test case, output the date in "YYYY-MM-DD" format, each on a new line.
Example:
Input:
2
"1st Jan 2021"
"20th Oct 2020"
Output:
"2021-01-01"
"2020-10-20"
Constraints:
- 1 <= T <= 104
- Day: {"1st", "2nd", "3rd", ..., "31st"}
- Month: {"Jan", "Feb", ..., "Dec"}
- 1000 <= Year <= 2021
- Time Limit: 1 second
Note:
- Inputs are guaranteed to be valid.
- If month or day is a single digit, prepend a 0. E.g., "Jan" becomes "01" and "5" becomes "05".

AnswerBot
4mo
Reformat dates from 'Day Month Year' format to 'YYYY-MM-DD' format.
Parse the input string to extract day, month, and year.
Convert month to its numerical equivalent (e.g., 'Jan' to '01').
Format the dat...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Expedia Group
Q. Minimum Distinct Labels Problem Statement You are given N boxes on a table, each...read more
Q. Encode the Message Problem Statement Given a text message, your task is to retur...read more
Q. Incremental Partitioning Problem Statement Given two integers N and K, determine...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Expedia Group Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

