You're helping at a farmers market and have a basket that can carry up to 5000 units of weight. In front of you are several apples, each with different weights, and you want to maximize the number of apples you can fit in your basket.
Given an integer array weight where weight[i] represents the weight of the i-th apple, return the maximum number of apples you can put in the basket without exceeding the weight limit.
Goal: Maximize the count of apples, not the total weight.
Example: If you have apples with weights [100, 200, 150, 1000] and your basket capacity is 5000, you should pick the lighter apples first: [100, 200, 150] gives you 3 apples with total weight 450, which is better than picking the heavy apple [1000] which only gives you 1 apple.
Input & Output
Constraints
- 1 โค weight.length โค 104
- 1 โค weight[i] โค 104
- Basket capacity is always 5000