Very simple Java O(n) solution using two pointers
\nclass Solution {\n    public List<Integer> findClosestElements(int[] arr, int k, int x) {\n        int lo = 0;\n\t\tint hi = arr.length - 1;\n\t\twhile (hi - 
```\nclass Solution {\n    public List<Integer> findClosestElements(int[] arr, int k, int x) {\n        int lo = 0;\n\t\tint hi = arr.length - 1;\n\t\twhile (hi - lo >= k) {\n\t\t\tif (Math.abs(arr[lo] - x) > Math.abs(arr[hi] - x)) {\n\t\t\t\tlo++;\n\t\t\t} else {\n\t\t\t\thi--;\n\t\t\t}\n\t\t}\n\t\tList<Integer> result = new ArrayList<>(k);\n\t\tfor (int i = lo; i <= hi; i++) {\n\t\t\tresult.add(arr[i]);\n\t\t}\n\t\treturn result;\n    }\n}\n```
[]