Skip to main content
LeetCode 1196, Easy. Topics: Array, Greedy, Sorting. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:

Problem

You have some apples and a basket that can carry up to 5000 units of weight. Given an integer array weight where weight[i] is the weight of the i-th apple, return the maximum number of apples you can put in the basket.

Examples

Constraints

  • 1 <= weight.length <= 10^3
  • 1 <= weight[i] <= 10^3

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026