1403. Minimum Subsequence in Non-Increasing Order Easy
1/**
2 * [1403] Minimum Subsequence in Non-Increasing Order
3 *
4 * 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.
5 * 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.
6 * Note that the solution with the given constraints is guaranteed to be unique. Also return the answer sorted in non-increasing order.
7 *
8 * Example 1:
9 *
10 * Input: nums = [4,3,10,9,8]
11 * Output: [10,9]
12 * Explanation: The subsequences [10,9] and [10,8] are minimal such that the sum of their elements is strictly greater than the sum of elements not included. However, the subsequence [10,9] has the maximum total sum of its elements.
13 *
14 * Example 2:
15 *
16 * Input: nums = [4,4,7,6,7]
17 * Output: [7,7,6]
18 * Explanation: The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to be returned in non-decreasing order.
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= nums.length <= 500
24 * 1 <= nums[i] <= 100
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/
30// discuss: https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn min_subsequence(nums: Vec<i32>) -> Vec<i32> {
36 vec![]
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_1403() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.