JAVA || Easy Solution
\tPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n    public List<Integer> findClosestElements(int[] arr, int k, int x) {\n        int xIndex = findElement(arr,
\tPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n    public List<Integer> findClosestElements(int[] arr, int k, int x) {\n        int xIndex = findElement(arr, x);\n\n        int lowerBound = xIndex - k < 0 ? 0 : xIndex - k;\n        int upperBound = xIndex + k > arr.length - 1 ? arr.length - 1 : xIndex + k;\n    \n        while(lowerBound + k <= upperBound) {\n            if(Math.abs(arr[lowerBound] - x) <= Math.abs(arr[upperBound] - x)) {\n                upperBound--;\n            } else {\n                lowerBound++;\n            }\n        }\n        \n        List<Integer> result = new LinkedList<Integer>();\n        for (int i = lowerBound; i <= upperBound; i++) {\n            result.add(arr[i]);\n        }\n        \n        return result;\n    }\n    \n    public int findElement(int[] arr, int target) {\n        int left = 0;\n        int right = arr.length - 1;\n        \n        while(left + 1 < right) {\n            int mid = left + (right - left) /2;\n            \n            if(arr[mid] == target) {\n                return mid;\n            } else if(arr[mid] > target) {\n                right = mid;\n            } else {\n                left = mid;\n            }\n        }\n        \n        if (Math.abs(arr[left] - target) > Math.abs(arr[right] - target)){\n            return right;\n        } else {\n            return left;\n        }\n    }\n}\n```
['Java']