Consider a set of m x n groups, each group having some number of points in a one-dimensional space. Each point is expressed by its coordinate on a line.
Write a program to choose exactly one point from every group to form a new set, such that the
distance between first and last points in the new set is the minimum possible.
Input:
Each line of input contains a list of space-separated integers for each group.
For example: 21 1 150 289 -321 160 3 30 170 2267
Output:
A space-separated sorted list of integers of the formed set.
For example: 1 3 6
Test 1
Test Input
21 1 150 289 -321
160 3 30
170 22 6 7Expected Output
1 3 6Test 2
Test Input
-24 -77 89 29 -3
187 -99 1Expected Output
-3 1Test 3
Test Input
6 19 95 76 24
79 53 2 9 16 91 73
81 14 65
22 60 37 32 99 71Expected Output
14 16 19 22Test 4
Test Input
-26 7 89 38 83 -90 87 87 59 66
0 81 -51 -45
-52 23 37
-7
-16 -46 70 21 18
77
-32 77
-47 -15 86 -5
38
64 32 53 78 -90 74 1 51 23 -95
-5 92 10 34 92 -70 37 -8 9
-64
4 74 87
-27 66 6 31 49 11 -59
91 98 59 -60 41 58 48 2 -1 90
23 -89 -45 -37 29 22 -66 -87
86
-69 0 -36 -43 33 -57
-44 21
28
-51 33 27 -56 43 -29 -33 -46
22 30 50 7 100
-55 -40 40 30 89
-45 3 -34
-30
16 33 14 -98
-4 54 28 -14 11Expected Output
37 37 38 38 39 40 41Could anyone please comment down the solution(Java) for this problem?