Leetcode 1519 Solution

This article provides solution to leetcode question 1519 (minimum-subsequence-in-non-increasing-order)

https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order

Solution

class Solution:
    def minSubsequence(self, nums: List[int]) -> List[int]:
        nums.sort(key=lambda v: -v)

        total = sum(nums)

        s = 0
        ans = []
        for v in nums:
            s += v
            ans.append(v)

            if 2 * s - 1 >= total:
                break
        return ans