Back
Close

Close Friends

Statement
You get in input on first line the number of incoming lines. then for N line you get a <<2 numbers separated by a space>> for example: [[5 3 ]] [[7 1]] [[4 8]] [[2 3]] You have to organise the list so that the last number from the array is greater by 1 or smaller by 1 of the first number of the next array. with the previous example it would be like: [[[5,3] [4,8] [7,1] [2,3]]]. You just have to return the sorted list of pair. the max and the min numbers (9 and 1) are followers, 9 can be the next to 1 and 1 can be the next to 9 for example it can be [[[5,9] [1,6]]].

Input description
<<Line 1: >> Number of pair <<N Line: >> Line of 2 number separated by a space

Output description
<< Line 1: >>Sorted List where last number of the arrays follow the first number of the next array in the format: [a,b] [b,c]

Constraints
1 <= [[a]],[[b]] >=9

Game modes
Fastest, Shortest, Reverse

Test cases
Test 1 Test
Input
4 5 3 7 1 4 8 2 3
Output
[5,3] [4,8] [7,1] [2,3]

Validator 1 Validator
Input
4 6 4 8 2 5 9 3 4
Output
[6,4] [5,9] [8,2] [3,4]

Test 2 Test
Input
5 9 8 2 9 7 3 5 3 4 6
Output
[9,8] [7,3] [4,6] [5,3] [2,9]

Validator 2 Validator
Input
5 8 7 1 8 6 2 4 2 3 5
Output
[8,7] [6,2] [3,5] [4,2] [1,8]

Test 3 Test
Input
4 9 6 4 1 5 3 4 6
Output
[4,1] [9,6] [5,3] [4,6]

Validator 3 Validator
Input
4 9 6 4 1 5 3 4 6
Output
[5,9] [1,7] [6,4] [5,7]

Test 4 Test
Input
5 2 9 1 3 1 9 8 1 4 5
Output
[1,9] [8,1] [2,9] [1,3] [4,5]

Validator 4 Validator
Input
5 2 3 9 4 5 6 3 1 4 1
Output
[3,1] [2,3] [4,1] [9,4] [5,6]

Solution language

Solution

Stub generator input