Longest Subsequence With Limited Sum
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an integer array nums of length n and an integer array queries of length m.
For each queries[j], find the maximum number of elements you can pick from nums (any positions, order does not matter) such that their sum is at most queries[j]. Return an array answer of length m where answer[j] is that maximum size.
Target O((n + m) log n) time.
Examples
Constraints
- n == nums.length, m == queries.length
- 1 <= n, m <= 1000
- 1 <= nums[i], queries[j] <= 10^6
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.