Timer is Running

Pair in Java
Submissions: 1565   Accuracy:


  Difficulty: Easy   Marks: 2

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.

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.

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

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


1 2 5 4 3 6

1 2 3 6 5 4

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.