package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/the-k-strongest-values-in-an-array/
 */
public class Problem1471 {
    public int[] getStrongest(int[] arr, int k) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1471 prob = new Problem1471();
        System.out.println(Arrays.toString(prob.getStrongest(new int[]{1,2,3,4,5}, 2))); // [5,1]
        System.out.println(Arrays.toString(prob.getStrongest(new int[]{1,1,3,5,5}, 2))); // [5,5]
        System.out.println(Arrays.toString(prob.getStrongest(new int[]{6,7,11,7,6,8}, 5))); // [11,8,6,6,7]
        System.out.println(Arrays.toString(prob.getStrongest(new int[]{6,-3,7,2,11}, 3))); // [-3,11,2]
        System.out.println(Arrays.toString(prob.getStrongest(new int[]{-7,22,17,3}, 2))); // [22,17]
    }
}

@@ -204,134 +204,131 @@
     
-// TODO%0A        return null
+Arrays.sort(arr);%0A        int m = arr%5B(arr.length - 1) / 2%5D
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1471 prob = new Problem1471
+int%5B%5D sorted = Arrays.stream(arr)%0A            .boxed
 ()
-;
 %0A   
@@ -336,508 +336,487 @@
     
-System.out.println(Arrays.toString(prob.getStrongest(new int%5B%5D%7B1,2,3,4,5%7D, 2))); // %5B5,1%5D%0A        System.out.println(Arrays.toString(prob.getStrongest(new int%5B%5D%7B1,1,3,5,5%7D, 2))); // %5B5,5%5D%0A        System.out.println(Arrays.toString(prob.getStrongest(new int%5B%5D%7B6,7,11,7,6,8%7D, 5))); // %5B11,8,6,6,7%5D%0A        System.out.println(Arrays.toString(prob.getStrongest(new int%5B%5D%7B6,-3,7,2,11%7D, 3))); // %5B-3,11,2%5D%0A        System.out.println(Arrays.toString(prob.getStrongest(new int%5B%5D%7B-7,22,17,3%7D, 2))); // %5B22,17%5D
+    .sorted((a, b) -%3E %7B%0A                int i = Math.abs(a - m);%0A                int j = Math.abs(b - m);%0A                int cmp = Integer.compare(j, i);%0A                if (cmp == 0) %7B%0A                    return Integer.compare(b, a);%0A                %7D%0A                return cmp;%0A            %7D)%0A            .mapToInt(a -%3E a).toArray();%0A        int%5B%5D answer = new int%5Bk%5D;%0A        for (int i = 0; i %3C k; i++) %7B%0A            answer%5Bi%5D = sorted%5Bi%5D;%0A        %7D%0A        return answer;
 %0A   

Solve problem 1471