Pair in Java
Submissions: 661   Accuracy:

69.16%

  Difficulty: Easy   Marks: 2
Associated Course(s):   Fork Java

Let's learn about Java Classes and how they can be useful.

Given an array A of N pairs of integers. The task is to sort the array on the basis of first element.

Hint: You may write a custom comparator. Read here.

Input:
First line of input contains number of testcase T. For each testcase, there will be two lines. First line of which contains N, number of pairs of integers and second line contains all the pairs.

Output:
For each testcase, there will be a single line containing all the pairs in required sorted form.

Constraints:
1 <= T <= 10
1 <= N <= 104
1 <= A[i] <= 105

Example:
Input:

1
3
1 2 5 4 3 6

Output:
1 2 3 6 5 4

Explanation:
Testcase 1:
Pairs are (1, 2), (5, 4), (3, 6). Sorting them on basis of first element, we have (1, 2), (3, 6), (5, 4).

** For More Input/Output Examples Use 'Expected Output' option **

Author: Dhiman Mayank


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.