{"id":"2ac6d486-ab26-42d1-acce-2a29d0e7e41b","name":"Sort Dates","description":"1. You are given an array(arr) of different dates in format DD-MM-YYYY.\r\n2. You have to sort these dates in increasing order.","inputFormat":"An Integer N \r\narr1\r\narr2..\r\nn integers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10000\r\nAll dates are between year 0 to year 2500","sampleCode":{"cpp":{"code":"#include <iostream>\r\n\r\n#include <vector>\r\n\r\nusing namespace std;\r\n\r\nvoid input(vector<int> &arr)\r\n{\r\n for (int i = 0; i < arr.size(); i++)\r\n {\r\n cin >> arr[i];\r\n }\r\n}\r\n\r\nvoid print(vector<int> &arr)\r\n{\r\n for (int i = 0; i < arr.size(); i++)\r\n {\r\n cout << arr[i] << endl;\r\n }\r\n cout << endl;\r\n}\r\n\r\n// used for swapping ith and jth elements of array\r\nvoid swap(vector<int> &arr, int i, int j)\r\n{\r\n cout << (\"Swapping index \" + to_string(i) + \" and index \" + to_string(j)) << endl;\r\n int temp = arr[i];\r\n arr[i] = arr[j];\r\n arr[j] = temp;\r\n}\r\n\r\nvoid sort01(vector<int> &arr)\r\n{\r\n\r\n}\r\n\r\nint main()\r\n{\r\n int n, m;\r\n cin >> n;\r\n vector<int> A(n, 0);\r\n input(A);\r\n\r\n sort01(A);\r\n print(A);\r\n return 0;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void sortDates(String[] arr) {\r\n // write your code here\r\n }\r\n\r\n public static void countSort(String[] arr,int div, int mod, int range) {\r\n // write your code here\r\n }\r\n\r\n public static void print(String[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n System.out.println(arr[i]);\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n String[] arr = new String[n];\r\n for (int i = 0; i < n; i++) {\r\n String str = scn.next();\r\n arr[i] = str;\r\n }\r\n sortDates(arr);\r\n print(arr);\r\n }\r\n\r\n}"},"python":{"code":"def Display(arr):\n for i in arr:\n print(i);\n \n\ndef countsort(arr, d, mod, r):\n # write your code here\n \n\ndef sortDates(arr):\n # write your code here\n\n\n\ndef main():\n n = int(input());\n arr = []\n for i in range(0, n):\n ele = (input());\n arr.append(ele);\n \n sortDates(arr);\n Display(arr);\n \n \nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n12041996\r\n20101996\r\n05061997\r\n12041989\r\n11081987","sampleOutput":"11081987\r\n12041989\r\n12041996\r\n20101996\r\n05061997","questionVideo":"https://www.youtube.com/embed/YdzCuP6LwVg?end=213","hints":[],"associated":[{"id":"233dff79-169b-40bb-9028-aadf59207635","name":"What is the time complexity of Sort Dates?","slug":"what-is-the-time-complexity-of-sort-dates","type":4},{"id":"5c81dd88-7fc4-45fe-a159-1d3fadcdcaae","name":"What is the space complexity of Sort Dates?","slug":"what-is-the-space-complexity-of-sort-dates","type":4},{"id":"70cebba8-e0ec-484e-ac20-da617b5bc8d3","name":"Is count sort a stable sort?","slug":"is-count-sort-a-stable-sort","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8e3abac7-a5ab-4090-abd1-b26ef8b53d70","name":"Time and Space Complexity","slug":"time-and-space-complexity","type":0},{"id":"6c6f624d-543b-45b2-b8e3-eea9fe362a35","name":"Sort Dates","slug":"sort-dates","type":1}],"next":{"id":"0cb4a244-f820-4073-a82b-7a3a5991d792","name":"SORT DATES","type":3,"slug":"sort-dates"},"prev":{"id":"21fd35d2-af8e-49c2-ae20-bf92620e9bd1","name":"Radix Sort","type":3,"slug":"radix-sort"}}}

Sort Dates

1. You are given an array(arr) of different dates in format DD-MM-YYYY. 2. You have to sort these dates in increasing order.

{"id":"2ac6d486-ab26-42d1-acce-2a29d0e7e41b","name":"Sort Dates","description":"1. You are given an array(arr) of different dates in format DD-MM-YYYY.\r\n2. You have to sort these dates in increasing order.","inputFormat":"An Integer N \r\narr1\r\narr2..\r\nn integers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10000\r\nAll dates are between year 0 to year 2500","sampleCode":{"cpp":{"code":"#include <iostream>\r\n\r\n#include <vector>\r\n\r\nusing namespace std;\r\n\r\nvoid input(vector<int> &arr)\r\n{\r\n for (int i = 0; i < arr.size(); i++)\r\n {\r\n cin >> arr[i];\r\n }\r\n}\r\n\r\nvoid print(vector<int> &arr)\r\n{\r\n for (int i = 0; i < arr.size(); i++)\r\n {\r\n cout << arr[i] << endl;\r\n }\r\n cout << endl;\r\n}\r\n\r\n// used for swapping ith and jth elements of array\r\nvoid swap(vector<int> &arr, int i, int j)\r\n{\r\n cout << (\"Swapping index \" + to_string(i) + \" and index \" + to_string(j)) << endl;\r\n int temp = arr[i];\r\n arr[i] = arr[j];\r\n arr[j] = temp;\r\n}\r\n\r\nvoid sort01(vector<int> &arr)\r\n{\r\n\r\n}\r\n\r\nint main()\r\n{\r\n int n, m;\r\n cin >> n;\r\n vector<int> A(n, 0);\r\n input(A);\r\n\r\n sort01(A);\r\n print(A);\r\n return 0;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void sortDates(String[] arr) {\r\n // write your code here\r\n }\r\n\r\n public static void countSort(String[] arr,int div, int mod, int range) {\r\n // write your code here\r\n }\r\n\r\n public static void print(String[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n System.out.println(arr[i]);\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n String[] arr = new String[n];\r\n for (int i = 0; i < n; i++) {\r\n String str = scn.next();\r\n arr[i] = str;\r\n }\r\n sortDates(arr);\r\n print(arr);\r\n }\r\n\r\n}"},"python":{"code":"def Display(arr):\n for i in arr:\n print(i);\n \n\ndef countsort(arr, d, mod, r):\n # write your code here\n \n\ndef sortDates(arr):\n # write your code here\n\n\n\ndef main():\n n = int(input());\n arr = []\n for i in range(0, n):\n ele = (input());\n arr.append(ele);\n \n sortDates(arr);\n Display(arr);\n \n \nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n12041996\r\n20101996\r\n05061997\r\n12041989\r\n11081987","sampleOutput":"11081987\r\n12041989\r\n12041996\r\n20101996\r\n05061997","questionVideo":"https://www.youtube.com/embed/YdzCuP6LwVg?end=213","hints":[],"associated":[{"id":"233dff79-169b-40bb-9028-aadf59207635","name":"What is the time complexity of Sort Dates?","slug":"what-is-the-time-complexity-of-sort-dates","type":4},{"id":"5c81dd88-7fc4-45fe-a159-1d3fadcdcaae","name":"What is the space complexity of Sort Dates?","slug":"what-is-the-space-complexity-of-sort-dates","type":4},{"id":"70cebba8-e0ec-484e-ac20-da617b5bc8d3","name":"Is count sort a stable sort?","slug":"is-count-sort-a-stable-sort","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8e3abac7-a5ab-4090-abd1-b26ef8b53d70","name":"Time and Space Complexity","slug":"time-and-space-complexity","type":0},{"id":"6c6f624d-543b-45b2-b8e3-eea9fe362a35","name":"Sort Dates","slug":"sort-dates","type":1}],"next":{"id":"0cb4a244-f820-4073-a82b-7a3a5991d792","name":"SORT DATES","type":3,"slug":"sort-dates"},"prev":{"id":"21fd35d2-af8e-49c2-ae20-bf92620e9bd1","name":"Radix Sort","type":3,"slug":"radix-sort"}}}
plane

Editor


Loading...

Sort Dates

easy

1. You are given an array(arr) of different dates in format DD-MM-YYYY. 2. You have to sort these dates in increasing order.

Constraints

1 <= N <= 10000 All dates are between year 0 to year 2500

Format

Input

An Integer N arr1 arr2.. n integers

Output

Check the sample output and question video.

Example

Sample Input

5 12041996 20101996 05061997 12041989 11081987

Sample Output

11081987 12041989 12041996 20101996 05061997

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode