Search
⌘K

Leetcode 2389. Longest Subsequence With Limited Sum

For each query, determine the maximum number of elements you can pick from nums (as a subsequence) whose sum is ≤ query — equivalent to choosing as many smallest elements as possible. Sort nums, build prefix sums, and for each query use binary search (or scan) on the prefix sums to get the count.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.