Skip to content
Onsite

Love of Samosa

EasyP3Coding

Amit has k units of money. There are n shops, each with exactly one samosa left, and prices[i] is the price at shop i. Return the largest number of samosas he can buy, buying at most one from each shop.

Example 1

Input
k = 10, prices = [3,5,2,8]
Output
3
Why
Buy the samosas costing 2, 3 and 5 for a total of 10.

Example 2

Input
k = 5, prices = [6,7]
Output
0

Constraints

  • 1 <= n <= 10^5
  • 1 <= k <= 10^9
  • 1 <= prices[i] <= 10^9

Hints

Run checks the 3 visible tests, Submit all 9.