classSolution:deffindClosestElements(self,arr: List[int],k:int,x:int) -> List[int]: left, right =0,len(arr)-1while left <= right: mid = (left + right) //2if arr[mid]< x: left = mid +1else: right = mid -1 center = left -1if left >0and (x - arr[left -1]) <= (arr[left]- x) else left left, right = center, center count =1while count != k:if left ==0: right +=1 count +=1elif right ==len(arr)-1: left -=1 count +=1else:if (x - arr[left -1]) <= (arr[right +1]- x): left -=1else: right +=1 count +=1return arr[left: right +1]