Java 4-Liner and O(n) Time Solution
\nO(nlog(n)) Time Solution:\n\n\npublic List<Integer> findClosestElements(List<Integer> arr, int k, int x) {\n     Collections.sort(arr, (a,b) -> a == b ? a - b
\nO(nlog(n)) Time Solution:\n\n```\npublic List<Integer> findClosestElements(List<Integer> arr, int k, int x) {\n     Collections.sort(arr, (a,b) -> a == b ? a - b : Math.abs(a-x) - Math.abs(b-x));\n     arr = arr.subList(0, k);\n     Collections.sort(arr);\n     return arr;\n}\n```\n\nO(n) Time Solution:\n\n```\npublic List<Integer> findClosestElements(List<Integer> arr, int k, int x) {\n    List<Integer> less = new ArrayList<>(), greater = new ArrayList<>(),\n                  lessResult = new LinkedList<>(), greaterResult = new LinkedList<>();\n \n    for (Integer i : arr) {\n        if (i <= x) less.add(i);\n        else greater.add(i);\n    }\n    \n    Collections.reverse(less);\n    int  i = 0, j = 0, n = less.size(), m = greater.size();\n    for (int size=0;size<k;size++) {\n        if (i < n && j < m) {\n            if (Math.abs(less.get(i) - x) <= Math.abs(greater.get(j) - x)) lessResult.add(less.get(i++));\n            else greaterResult.add(greater.get(j++));\n        }\n        else if (i < n) lessResult.add(less.get(i++));\n        else greaterResult.add(greater.get(j++));\n    }\n\n    Collections.reverse(lessResult);\n    lessResult.addAll(greaterResult);\n    return lessResult;\n}\n```\n\nNote that above solution can be improved using binary search under the assumption that we have O(1) access to elements in input list.
[]