Sort Big List Dates
Mary is a party-loving girl of the 21st Generation. She loves to attend parties and events with her family and friends. But she is terrible at remembering the dates of these events.
Mary has a list of dates of these events. Can you help her sort the list of dates to be easier for Mary to track the parties?
You are given an array ‘dates’ consisting of ‘N’ dates. You have to sort this array and print the array in sorted order.
For example:
If dates= [ [13,6,2007] , [2,6,2001] , [10,8,2019] , [1,6,2007] ]
Sorted Order of Dates will be :
dates = [ [ 2,6,2001] , [1,6,2007] , [13,6,2007] ]
Input Format:
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N,’ denoting the number of dates in the array.
The Next ‘N’ lines of each test case have three integers corresponding to date, month, and year.
Output Format:
For each test case, print ‘N’ lines for the sorted list elements, each line has three integers corresponding to date, month, and year.
Print the output of each test case in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= N <= 10^6
1 <= dates[i][0] <= 31
1 <= dates[i][1] <=12
2000 <= dates[i][2] <=2099
Time limit: 1 sec
CodingNinjas
author
2y
Custom sorting can be used here. Extract the days, months and years as sub-strings from the string then compare two strings by years, if years for two dates are equal then compare their months. If mon...read more
CodingNinjas
author
2y
Using Inbuilt Sort function
In this approach, we will sort the array using Inbuild Sort with the help of a Comparator.
A Comparator is a custom compare function that decides the order of sorting by con...read more
CodingNinjas
author
2y
Using Counting Sort
In this approach, we will use Counting Sort to sort the array. The Counting Sort is a non-comparison-based sorting method with linear time complexity. It is usually used with arrays...read more
Add answer anonymously...
Top Morgan Stanley Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Morgan Stanley Software Developer
>
Morgan Stanley Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app