easy java
\n    public List<Integer> findClosestElements(List<Integer> arr, int k, int x) {\n        List<Integer> result = new LinkedList<>();\n        TreeMap<Integer, 
```\n    public List<Integer> findClosestElements(List<Integer> arr, int k, int x) {\n        List<Integer> result = new LinkedList<>();\n        TreeMap<Integer, List<Integer>> map = new TreeMap<>();\n        for (int a : arr) {\n            int abs = Math.abs(a - x);\n            if (!map.containsKey(abs)) map.put(abs, new LinkedList<>());\n            map.get(abs).add(a);\n        }\n        for (Map.Entry<Integer, List<Integer>> e : map.entrySet()) {\n            for (int i : e.getValue()) {\n                result.add(i);\n                if (result.size() == k) break;\n            }\n            if (result.size() == k) break;\n        }\n        Collections.sort(result);\n        return result;\n    }\n```
[]