Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Pair in Java
Easy Accuracy: 63.53% Submissions: 1936 Points: 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.

Example 1:

Input:
3
1 2 5 4 3 6

Output:
1 2 3 6 5 4

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

Example 2:

Input:
2
4 8 2 24

Output:
2 24 4 8

Explanation:
Pairs are (4, 8), (2, 24). Sorting them on 
basis of first element, we have (4, 8), (2, 24).

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

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Pair in Java

Output Window