Goldman Sachs OA Problem
You are given a list of strings representing dates in the format "dd MMM yyyy" (e.g., "26 Nov 1920", "2 Jan 2023", "10 Aug 2024"). Your task is to convert these dates into the format "yyyy-mm-dd", where the month is represented by its integer number (e.g., Jan-01, Feb-02, ..., Dec-12).
Output each converted date on a separate line.
Input: ["26 Nov 1920", "2 Jan 2023", "10 Aug 2024"]
Output:
1920-11-26
2023-01-02
2024-08-10
Approach:
1.Firstly store the month with their corresponding number in the hashmap.
2.Split the date with space and it will create a string array of each date.
3.String dd=arr[0]//represents the date.
String mm=map.get(arr[1])//find the corresponding month number because we have to convert into the given format.
4.after this add them in the order yyyy-mm-dd like this.
Feel free to connect with me:
Amazing Solution
ReplyDelete