Subsequences have always been a concept that trips me up a bit. I don’t know why. But as with anything, the more time I spend working with subsequences, the more I slowly learn and get more comfortable with them.

Either way, the problem we are going to tackle today might seem complicated at first glance, and will provide a good challenge for our critical thinking skills (hopefully).

So, let’s get solving.


THE PROBLEM

Here is a link to the problem on LeetCode

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.

THE CONSTRAINTS

The provided constraints don’t really yield any noteworthy pieces of information, but as always let’s through each one and see if we can uncover any clues to a solution:

1 <= nums.length <= 500

The first constraint gives us a range of numbers we should expect in the nums array. With a lower limit of 1 <= nums.length, we don’t have to worry about nums being empty or not having any elements. The upper limit of nums.length <= 500 also doesn’t give us any particular information other than the largest amount of elements we would need to iterate through.

1 <= nums[i] <= 100

The second constraint is the range for elements in nums. We learn that we won’t have to deal with any negative numbers or if an element in nums is 0, as the lower limit of elements in nums is 1 <= nums[i]. With the upper limit of nums[i] <= 100, we also do not have to worry about any really big numbers. Relatively speaking, an upper limit of 100 is quite small.

#austin-smith #programming #javascript #leetcode #minimum-subsequence

JavaScript Problem Solvers: Minimum Subsequence
1.25 GEEK