Python Solution
Hope it helps\n\n\nclass Solution:\n    def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n\t\t# first binary search where the value \
Hope it helps\n\n```\nclass Solution:\n    def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n\t\t# first binary search where the value \'x\' should be in the sorted array\n        n = len(arr)\n        low, high = 0, n - 1\n        while low <= high:\n            mid = low + (high - low) // 2\n            if arr[mid] == x:\n                start, end = mid - 1, mid + 1\n                k -= 1\n                break\n            elif arr[mid] < x:\n                low = mid + 1\n            else:\n                high = mid - 1\n                \n        if low > high:\n            start = high\n            end = low\n        #  after we found where \'x\' should be in the sorted array we expand to the left and to the right to find the next values until k (using two pointers start, end)\n        while k > 0:\n            if start == -1:\n                end += 1\n            elif end == n:\n                start -= 1\n            else:\n                if abs(arr[start] - x) <= abs(arr[end] - x):\n                    start -= 1\n                else:\n                    end += 1\n            k -= 1\n        return arr[start + 1:end]\n\n```
['Binary Search', 'Binary Tree', 'Python', 'Python3']