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...
Expedia Group Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Minimum Distinct Labels Problem Statement You are given N boxes on a table, each...read more
A Software Developer Intern was asked Q. Encode the Message Problem Statement Given a text message, your task is to retur...read more
A Software Developer Intern was asked Q. Incremental Partitioning Problem Statement Given two integers N and K, determine...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Minimum Distinct Labels Problem Statement You are given N boxes on a table, each...read more
A Software Developer Intern was asked Q2. Encode the Message Problem Statement Given a text message, your task is to retur...read more
A Software Developer Intern was asked Q3. Incremental Partitioning Problem Statement Given two integers N and K, determine...read more
>
Expedia Group Software Developer Intern Interview 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

