The Reformat Date problem converts a date string from "Day Month Year" format (e.g., "20th Oct 2052") to "YYYY-MM-DD" format. This easy coding problem tests string parsing, month name mapping, and date formatting. The string interview pattern is demonstrated.
Goldman Sachs, TikTok, Oracle, Expedia, and Adobe ask this to verify string manipulation and date conversion skills — practical programming fundamentals for backend and data engineering roles.
String split + month map + format. Split the string by spaces into [day_str, month_str, year]. Build a month-name-to-number map. Extract numeric day from day_str (remove ordinal suffix 'st','nd','rd','th'). Format: f"{year}-{month:02d}-{day:02d}".
s="20th Oct 2052". Split: ["20th","Oct","2052"]. Day=20. Month={Oct:10}=10. Year=2052. Output: "2052-10-20".
s="6th Jun 1933". Day=6. Month=6. Output: "1933-06-06" (zero-padded).
Date reformatting tests practical string manipulation: splitting, mapping, and formatting. Build the month map as a dictionary at initialization. The ordinal suffix (st/nd/rd/th) is always 2 characters — strip the last 2 chars from day_str. Always zero-pad day and month with 2 digits. Practice similar "convert date format" problems in different language APIs.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Decrypt String from Alphabet to Integer Mapping | Easy | Solve | |
| Number of Valid Words in a Sentence | Easy | Solve | |
| Consecutive Characters | Easy | Solve | |
| Valid Word | Easy | Solve | |
| Length of Last Word | Easy | Solve |