Java TreeMap
```\nclass Solution {\n    public int[] getStrongest(int[] arr, int k) {\n        int[] c=new int[arr.length];\n        for(int i=0;i<arr.length;i++){\n        
```\nclass Solution {\n    public int[] getStrongest(int[] arr, int k) {\n        int[] c=new int[arr.length];\n        for(int i=0;i<arr.length;i++){\n            c[i]=arr[i];\n        }\n        Arrays.sort(arr);\n        int med=arr[(arr.length-1)/2];\n        TreeMap<Integer,ArrayList<Integer>> map=new TreeMap<>();        \n    for(int i=0;i<arr.length;i++){\n        if(!map.containsKey(Math.abs(c[i]-med))){\n        map.put(Math.abs(c[i]-med),new ArrayList<>());\n    }\n        map.get(Math.abs(c[i]-med)).add(c[i]);\n    }\n        // System.out.println(map);\n        int[] a=new int[k];\n        int i=0;\n        while(k>0){\n            int d=map.lastKey(); \n            Collections.sort(map.get(d));\n             // System.out.println(d);\n            for(int p=map.get(d).size()-1;p>=0&&k>0;p--){\n                a[i]=map.get(d).get(p);\n                i++;\n                k--;\n            }\n            map.remove(d);\n        }\n        return a;\n    }\n}
[]