Free written solutionLongest Subsequence With Limited Sum (LeetCode 2389): Solution and Explanation
For each query, find the most elements of nums you can pick so that their sum stays at most the query. With nums = [4,5,2,1] and queries = [3,10,21] the answer is [2,3,4].
Read the intuition, approach, code and complexity →