Simple Python Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nThink of the median as a balancing point in the array. Elements on one side of the medi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink of the median as a balancing point in the array. Elements on one side of the median have maximum element than the other side. Stronger elements are those that are farther away from the median, causing an imbalance.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. arr.sort(): This sorts the input list arr in ascending order. Sorting the list allows for easier comparison and selection of the closest elements.\n\n2. median = arr[(len(arr) - 1) // 2]: This calculates the median of the sorted list arr. If the length of the list is odd, the median is the element at the middle index. If the length is even, it\'s the average of the two middle elements.\n3. Initialize ans, left, and right: ans will store the k closest elements, and left and right are pointers that help traverse the sorted list from both ends towards the middle.\n4. while left <= right:: This initiates a loop that continues as long as the pointers left and right haven\'t crossed each other.\n5. Inside the loop:\n\n- abs(arr[left] - median) calculates the absolute difference between the element at index left and the median.\n\n- abs(arr[right] - median) calculates the absolute difference between the element at index right and the median.\n- The if condition compares the absolute differences of the elements at the left and right positions. The element with the smaller absolute difference is considered closer to the median.\n- If the element at the left position is closer, it\'s appended to the ans list, and left is incremented.\n- If the element at the right position is closer, it\'s appended to the ans list, and right is decremented.\n- return ans[:k]: Finally, the function returns the first k elements from the ans list, which are the k closest elements to the median.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n log n)\nRuntime 858ms ,Beats 90.34% of users with Python3\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\nMemory 29.46mb , Beats 97.16% of users with Python3\n\n# Code\n```\nclass Solution:\n    def getStrongest(self, arr: List[int], k: int) -> List[int]:\n        arr.sort()\n        median = arr[(len(arr) - 1) //2]\n        ans = []\n        left = 0 \n        right = len(arr)-1\n        while left<=right:\n            if abs(arr[left] - median) > abs(arr[right] - median):\n                ans.append(arr[left])\n                left+=1\n            else:\n                ans.append(arr[right])\n                right-=1\n        return ans[:k]\n```
['Array', 'Two Pointers', 'Sorting', 'Python3']