Java PQ Solution (N(Log(K))
```\nclass Solution {\n    public List findClosestElements(int[] arr, int k, int x) {\n        \n        Queue queue = new PriorityQueue<>((a,b) -> b[1]!=a[1] ?
```\nclass Solution {\n    public List<Integer> findClosestElements(int[] arr, int k, int x) {\n        \n        Queue<int[]> queue = new PriorityQueue<>((a,b) -> b[1]!=a[1] ? b[1] - a[1] : a[0] - b[0]);\n\t\t\n        //Defined a priority queue which will always keep the maximum diff element in the top of the \n\t\t// queue whenever we find a element with diff smaller we will pop the queue and add the current \n\t\t// element .\n\n        for(int i=0;i<arr.length;i++){\n            if(queue.size() == k){\n                if(Math.abs(arr[i]-x) < queue.peek()[1]){\n                    queue.poll();\n                    queue.add(new int[]{i,Math.abs(x-arr[i])});\n                }\n            }else{\n                queue.add(new int[]{i,Math.abs(x-arr[i])});\n            }\n            \n        }\n        List<Integer> result = new ArrayList();\n        int size = queue.size();\n        for(int i=0;i<size;i++){\n            result.add(arr[queue.poll()[0]]);\n        }\n        Collections.sort(result);\n        return result;\n    }\n}
['Heap (Priority Queue)', 'Java']