? Q1. Given a 2D matrix A[1...n][3] in which the total number of elements in each row is 3. Sort the 2D matrix keeping t
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
? Q1. Given a 2D matrix A[1...n][3] in which the total number of elements in each row is 3. Sort the 2D matrix keeping t
10 dislike
? Q1. Given a 2D matrix A[1...n][3] in which the total number of elements in each row is 3. Sort the 2D matrix keeping these things in mind: • Sort the matrix by Ascending order of their first value A[1...n][0]. • If A[0] == A[j][0], then sort the matrix by Ascending order of their second value A[1...n][1]. • If A[1] == A[j][1], then sort the matrix by Descending order of their third value A[1..n][2]. TestCase: n=5 111 116 123 311 319 O/P: 116 111 123 319 311 Explanation: • In a given test case, [1 1 1] is compared with [1 1 6] as from 3rd point A[0][0]==A[1][0] & A[0][1] ==A[1][1] so sort this with descending order so [1 1 6] comes before [1 1 1]. • Same goes for [3 1 1] & [3 1 9]. 00 ENG IN 22:39 05-06-2022