Java O(nlogK) solution !! Used Priority Queue !! Java accepted solution
\tclass Solution {\n    \n    class Pair{\n        int key;\n        int value;\n        \n        Pair(int key, int value){\n            this.key = key;\n     
\tclass Solution {\n    \n    class Pair{\n        int key;\n        int value;\n        \n        Pair(int key, int value){\n            this.key = key;\n            this.value = value;\n        }\n        \n    }\n    \n    public List<Integer> findClosestElements(int[] arr, int k, int x) {\n        int n = arr.length;\n        List<Integer> list = new ArrayList<>();\n        \n        // make max priority queue\n        PriorityQueue<Pair> pq = new PriorityQueue<>(\n            new Comparator<Pair>(){\n                public int compare(Pair a, Pair b){\n                    // if both the keys are same then compare on the bases of their values\n                    if((b.key - a.key) == 0)\n                        return b.value - a.value;\n                    return b.key - a.key;\n                }\n        });\n        \n        for(int i: arr){\n            pq.add(new Pair(Math.abs(i-x), i));\n            \n            if(pq.size() > k)\n                pq.poll();\n        }\n        \n        while(pq.size() != 0){\n            Pair p = pq.poll();\n            list.add(p.value);\n        }\n        \n        Collections.sort(list);\n        return list;\n    }\n\t}
['Two Pointers', 'Heap (Priority Queue)', 'Java']