2171. Removing Minimum Number of Magic Beans

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

On This Page

LeetCode problem 2171

class Solution:
    def minimumRemoval(self, beans: List[int]) -> int:
        beans.sort()
        s, n = sum(beans), len(beans)
        return min(s - x * (n - i) for i, x in enumerate(beans))