Minimum Subsequence in Non-Increasing Order Problem

Minimum Subsequence in Non-Increasing Order Problem — ExecCode Easy DSA Practice

Solve the Minimum Subsequence in Non-Increasing Order problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are 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. Your task is to 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.

Examples

Input {"nums": [4, 3, 10, 9, 8]}; Output [10, 9]. Input {"nums": [4, 4, 7, 6, 7]}; Output [7, 7, 6]

Constraints

1 <= nums.length <= 500 1 <= nums[i] <= 100

Practice Minimum Subsequence in Non-Increasing Order free on ExecCode. Browse DSA problems, topic map, and placement guides.