The Minimum Subsequence in Non-Increasing Order problem asks you to find the smallest subsequence of an array (by length) such that its sum is strictly greater than the sum of the remaining elements. If multiple subsequences have the same minimum length, return the one with the largest sum. This Minimum Subsequence in Non-Increasing Order coding problem is a beginner-friendly greedy problem relying on sorting.
Mercari and Amazon use this as a screening question to verify foundational sorting and greedy skills. It confirms candidates can translate "maximize partial sum with fewest elements" into a simple greedy: take the largest elements first until the condition is satisfied. The array, sorting, and greedy interview pattern is directly applicable.
Sort descending, then greedily pick elements from the front. Maintain a running sum of selected elements and the total sum. Keep picking elements until selectedSum > totalSum - selectedSum. The selected elements form the answer subsequence. Return them in non-increasing order (already sorted from step 1).
Array: [4, 3, 10, 9, 8]. Total sum = 34.
Sort descending: [10, 9, 8, 4, 3].
Easy greedy problems test code fluency more than algorithmic depth. Practice writing clean, concise solutions: sort, accumulate, stop at condition. The key skill is translating the word problem ("sum strictly greater than remaining") into a precise mathematical condition and implementing it without unnecessary complexity. Getting easy problems right quickly and cleanly is crucial in time-pressured interviews.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Buy Two Chocolates | Easy | Solve | |
| Minimum Cost of Buying Candies With Discount | Easy | Solve | |
| Maximum Units on a Truck | Easy | Solve | |
| Apple Redistribution into Boxes | Easy | Solve | |
| How Many Apples Can You Put into the Basket | Easy | Solve |