Find the Earliest Formatted Date
Updated
Problem statement
Given an array of formatted calendar dates, return the earliest date as its original string. Compare actual calendar chronology, not alphabetical string order.
For this exercise, every input is a valid Gregorian date in exact DD Mon YYYY format: a two-digit day, one space, a case-sensitive English month abbreviation, one space and a four-digit year. Month abbreviations are Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec. Gregorian leap-year rules apply. Dates have no time or time zone.
Return an empty string when the input array is empty. For equal earliest dates, choose the first original occurrence; preserve its exact formatting. Leave the input array unchanged.
Function
earliestDate(dates: String[]) → StringExamples
Example 1
dates = ["13 Jan 2014","24 Dec 1994","08 Feb 2000"]return = "24 Dec 1994"The years are 2014,1994,2000. The 1994 date is earliest, so return the exact original string 24 Dec 1994.
Example 2
dates = ["31 Jan 2024","01 Feb 2024","02 Jan 2024"]return = "02 Jan 2024"All years are 2024. January precedes February, and within January, day 2 precedes day 31. Return 02 Jan 2024, preserving the original zero-padded input string.
Constraints
- For this exercise, assume 0 <= dates.length <= 500.
- Every date string has exactly 11 characters.
- Every string is a valid Gregorian date in exact DD Mon YYYY format, with case-sensitive English month abbreviations Jan through Dec and a year between 1600 and 9999, inclusive.
More Morgan Stanley Online Assessment questions
- Three-Resource 0/1 KnapsackOA · Seen Sep 2026
- Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
- Maximum Total of Nonadjacent RatingsOA · Seen Jul 2026
- Count Shipment SchedulesOA · Seen Apr 2026
- Delete and EarnOA · Seen Apr 2026
- Interleave Array HalvesOA · Seen Apr 2026
- Get Patch SequenceOA · Seen Feb 2025
- String Subsequences 🐳OA · Seen Mar 2024
- Binary Tree Level OrderOA · Seen Feb 2024
- Merge IntervalsOA · Seen Feb 2024
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Find a File in a Directory SnapshotCresta · OACresta interview questions
- Flat JSON Value DifferencesChubb · OAChubb interview questions
- Road Trip (Analyst Program :PBlackRock · OABlackRock interview questions
- Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
- Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
- Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
- Most Frequent CharacterMicrosoft · OAMicrosoft interview questions
Interview reports that mention this question
Morgan Stanley interview experiences
- Morgan Stanley New Grad Technology Analyst: 2 Experiences
- Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)
- Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
- Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
- Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)