1471. The k Strongest Values in an Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1471

class Solution:
    def getStrongest(self, arr: List[int], k: int) -> List[int]:
        arr.sort()
        m = arr[(len(arr) - 1) >> 1]
        arr.sort(key=lambda x: (-abs(x - m), -x))
        return arr[:k]