python3 O(n) time complexity and efficient algorithm
```\nclass Solution:\n    def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n        left=0\n        right=len(arr) - 1\n        while
```\nclass Solution:\n    def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n        left=0\n        right=len(arr) - 1\n        while right-left+1 > k:\n            if  abs(x-arr[left]) > abs(x-arr[right]):\n                left+=1\n            else:\n                right-=1\n        return arr[left:right+1]\n\n# time and space complexity \n# time: O(n)\n# space: O(1)\n
['Python', 'Python3']