Party or Not
MediumP3Coding
costs[i] is what it costs to host friend i at a party. You want to host exactly c of the n friends and can spend at most r rupees in total.
Return true if some choice of c friends costs at most r in total, otherwise false.
Example 1
- Input
- costs = [5,3,8,2], c = 2, r = 6
- Output
- true
- Why
- Friends costing 3 and 2 total 5, which is within 6.
Example 2
- Input
- costs = [5,3,8,2], c = 2, r = 4
- Output
- false
Example 3
- Input
- costs = [7], c = 1, r = 7
- Output
- true
Constraints
- 1 <= c <= costs.length <= 10^5
- 1 <= costs[i] <= 10^4
- 0 <= r <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.