Minimum Subsequence in Non-Increasing Order - Problem

Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non-included elements in such subsequence.

If there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum total sum of all its elements.

A subsequence of an array can be obtained by erasing some (possibly zero) elements from the array.

Note that the solution with the given constraints is guaranteed to be unique. Also return the answer sorted in non-increasing order.

Input & Output

Example 1 — Basic Case
$ Input: nums = [4,3,10,9]
Output: [10,9]
💡 Note: Total sum = 26. We need subsequence sum > remaining sum. Taking [10,9] gives sum=19 > remaining sum=7. This is minimum size (2) and already sorted in non-increasing order.
Example 2 — Single Element
$ Input: nums = [4,4,7,6,7]
Output: [7,7,6]
💡 Note: Total sum = 28. Need sum > 14. Taking largest elements [7,7,6] gives sum=20 > remaining sum=8. This achieves the required condition with minimum size.
Example 3 — Edge Case
$ Input: nums = [6]
Output: [6]
💡 Note: With only one element, we must take it. Sum=6 > remaining sum=0, so [6] is the answer.

Constraints

  • 1 ≤ nums.length ≤ 500
  • 1 ≤ nums[i] ≤ 100

Visualization

Tap to expand
Find Minimum Dominant SubsequenceInput Array:43109Total Sum = 26Goal:Subsequence Sum > Remaining SumSolution:109Remaining:43Subsequence: 10 + 9 = 19Remaining: 4 + 3 = 719 > 7 ✓Output: [10, 9]
Understanding the Visualization
1
Input Array
Given array with total sum calculation
2
Find Dominant Subsequence
Select minimum elements whose sum > remaining sum
3
Output
Return subsequence sorted in non-increasing order
Key Takeaway
🎯 Key Insight: Greedily pick the largest elements first to minimize subsequence size while maximizing sum
Asked in
Amazon 15 Microsoft 8
28.5K Views
Medium Frequency
~12 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen