Python Easy to Understand Solution
Finding the postion of \'x\' in the array using binary search.\n* Then doing a linear search for the closest element indexes.\n\nclass Solution:\n    def findCl
* Finding the postion of \'x\' in the array using binary search.\n* Then doing a linear search for the closest element indexes.\n```\nclass Solution:\n    def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n        n = len(arr)\n        lo, hi = 0, n\n        while lo < hi:\n            mid = lo + hi >> 1\n            if arr[mid] < x:\n                lo = mid + 1\n            else:\n                hi = mid\n        left, right = lo - 1, lo\n        while k:\n            leftElem = arr[left] if left >= 0 else float(\'-inf\')\n            rightElem = arr[right] if right < n else float(\'inf\')\n            if x - leftElem <= rightElem - x:\n                left -= 1\n            else:\n                right += 1\n            k -= 1\n        return arr[left+1:right]\n```\nRuntime: 304 ms, faster than 93.15% of Python3 online submissions for Find K Closest Elements.\nMemory Usage: 15.1 MB, less than 79.23% of Python3 online submissions for Find K Closest Elements.
['Python3']