#1403
Easy Algorithms Minimum subsequence in non increasing order
Array Greedy Sorting
73.6% acceptance
Feb 25, 2026
634
512
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.
Solution
Rust
Time O(n)
Space O(n)
impl Solution {
pub fn min_subsequence(mut nums: Vec<i32>) -> Vec<i32> {
nums.sort_unstable_by(|a, b| b.cmp(a));
let total: i32 = nums.iter().sum();
let mut chosen_sum = 0;
let mut result = vec![];
for n in nums {
chosen_sum += n;
result.push(n);
if chosen_sum > total - chosen_sum { break; }
}
result
}
}