✔ JAVA | 2 Solutions | 2-Pointer and Priority-Queue
2-Pointer Approach\n\nclass Solution {\n    public int[] getStrongest(int[] arr, int k) {\n        int[] result = new int[k];\n        int n = arr.length, left 
**2-Pointer Approach**\n```\nclass Solution {\n    public int[] getStrongest(int[] arr, int k) {\n        int[] result = new int[k];\n        int n = arr.length, left = 0, right = n - 1, idx = 0;\n        Arrays.sort(arr);\n        int median = arr[(n - 1) / 2];\n        while (left <= right) {\n            int diff_l = Math.abs(arr[left] - median);\n            int diff_r = Math.abs(arr[right] - median);\n            \n            if (diff_r > diff_l)\n                result[idx++] = arr[right--];\n            else if (diff_l > diff_r)\n                result[idx++] = arr[left++];\n            else if (arr[right] > arr[left])\n                result[idx++] = arr[right--];\n            else \n                result[idx++] = arr[left++];\n            if (idx == k)\n                break;\n        }\n        return result;\n    }\n}\n```\n**Priority-Queue Approach**\n```\nclass Pair {\n    int diff;\n    int ele;\n    public Pair(int d, int e) {\n        this.diff = d;\n        this.ele = e;\n    }\n}\nclass MyComparator implements Comparator<Pair> {\n    public int compare (Pair p, Pair q) {\n        if (p.diff == q.diff)\n            return q.ele - p.ele;\n        return q.diff - p.diff;\n    }\n}\nclass Solution {\n    public int[] getStrongest(int[] arr, int k) {\n        PriorityQueue<Pair> queue = new PriorityQueue(new MyComparator());\n        Arrays.sort(arr);\n        int median = arr[(arr.length - 1) / 2];\n        for (int i = 0; i < arr.length; i++)\n            queue.offer(new Pair(Math.abs(arr[i] - median), arr[i]));\n        int[] result = new int[k];\n        for (int i = 0; i < k;  i++)\n            result[i] = queue.poll().ele;\n        return result;\n    }\n}\n```\nPlease **upvote** :-)
['Array', 'Java']