Python | Binary Search | O(logn+k)
\nclass Solution:\n    def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n        beg = k\n        end = len(arr)\n        while beg <
```\nclass Solution:\n    def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n        beg = k\n        end = len(arr)\n        while beg < end:\n            mid = (beg+end) // 2\n            a = arr[mid]\n            b = arr[mid-k]\n            if (a-x) >= (x-b):\n                end = mid\n            else:\n                beg = mid + 1\n        return arr[beg-k:end]\n```\nPlease upvote if you get it.
['Binary Tree', 'Python']