Clean O(logN) solution in Python
\nThe O(logN) logic for this problem would dwell down to finding k elements by finding the starting element.\n\nIf the starting element is found, [start, start+
\nThe O(logN) logic for this problem would dwell down to finding k elements by finding the starting element.\n\nIf the starting element is found, [start, start+k] elements can be returned. \n\nGiven that **k << len(arr)**; we can always use the **hi index as length(arr)-k and lo=0**\n\nFor cases where the target is off the extremes we\'ll end up with k elements. \nBut for the cases where the target is within exactly or sparsely equal to one of the elements in the array; we need to \nshuffle lo and hi accordingly\n\nConsider binary search paradigm:\n\n**if arr[mid] is farther from target than arr[mid+k] which is k places ahead of mid then we need to pull lo\nto mid with 1 offset; otherwise we can pull hi at mid**. \nat the end we\'ll end up with a value contained by lo\'s index which can be the starting index of our solution\n\n```py3\nclass Solution(object):\n    def findClosestElements(self, arr, k, x):\n        """\n        :type arr: List[int]\n        :type k: int\n        :type x: int\n        :rtype: List[int]\n        """\n        lo, hi = 0, len(arr)-k\n        while lo<hi:\n            mid = (lo + hi)//2\n            if x-arr[mid]>arr[mid+k]-x:\n                lo = mid + 1\n            else:\n                hi = mid\n        return arr[lo:lo+k]\n```
['Python', 'Python3']