Write a Numeric Date in Words
Updated
Problem statement
date is a real calendar date written as "MM-DD-YYYY", with a two-digit month, a two-digit day and a four-digit year. Return it in words: the full English month name, a space, the day without leading zeros followed by its ordinal suffix, a comma, a space, and the year.
The suffix is st, nd or rd for days ending in 1, 2 or 3, and th otherwise. Days 11, 12 and 13 always take th.
Function
formatDate(date: String) → StringExamples
Example 1
date = "03-22-2024"return = "March 22nd, 2024"Month 03 is March. Day 22 ends in 2, so it takes nd. The year stays as written.
Example 2
date = "11-13-1999"return = "November 13th, 1999"Day 13 ends in 3, but 11, 12 and 13 are exceptions that always take th, so it is 13th, not 13rd.
Example 3
date = "07-01-2031"return = "July 1st, 2031"The leading zero of the day is dropped: 01 becomes 1st.
Example 4
date = "10-03-2012"return = "October 3rd, 2012"Day 03 ends in 3 and is not a teen, so it takes rd: 3rd.
Example 5
date = "12-11-1990"return = "December 11th, 1990"Day 11 ends in 1, but like 12 and 13 it takes th, so it is 11th, not 11st.
Constraints
datehas the form"MM-DD-YYYY"and names a real date.- The year is between
1900and2100.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Christmas Tree with N TiersVerily · ONSITE INTERVIEW
- Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
- Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
- Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
- Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
- Implement tail -nConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Valid ParenthesesEPAM · ONSITE INTERVIEWEPAM interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences