Clean Java solution. Binary Search + LinkedList
\npublic List<Integer> findClosestElements(int[] arr, int k, int x) {\n        LinkedList<Integer> ans = new LinkedList<>();\n        if (arr == null || arr.len
```\npublic List<Integer> findClosestElements(int[] arr, int k, int x) {\n        LinkedList<Integer> ans = new LinkedList<>();\n        if (arr == null || arr.length == 0) return ans;\n        int index = Arrays.binarySearch(arr, x);\n        int l = -1, r = -1;\n        if (index < 0) {\n            index = Math.abs(index) - 1;\n            r = index;\n        } else {\n            ans.add(arr[index]);\n            k--;\n            r = index + 1;\n        }\n        l = index - 1;\n\n        while(k > 0) {\n            int absL = l< 0 ? Integer.MAX_VALUE : Math.abs(x - arr[l]);\n            int absR = r > arr.length - 1 ? Integer.MAX_VALUE : Math.abs(x - arr[r]);\n\n            if (absL <= absR) {\n                ans.addFirst(arr[l--]);\n            } else {\n                ans.add(arr[r++]);\n            }\n            k--;\n        }\n\n        return ans;\n    }\n```
[]