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
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.
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 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
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.
CASE 011: Snakes On An Inclined Plane. On a plane there are n points with integer coordinates points[i] = [xi, yi]. Your task is to find the minimum time in seconds to visit all points. I seemed to have fallen into a web of nested arrays, matrices and pattern matching. Today’s problem isn’t as complex as last week’s Onion Swap hullabaloo, but technically still deals with matrices. Technically technically, we are dealing with a graph, but at the same time, we aren’t.