Problem statement

https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket/

Solution

Just try to put the smallest apples.

Complexity

Time complexity is O(n log n), space is O(n).

Code

from bisect import bisect

class Solution:
    def maxNumberOfApples(self, arr):
        arr = list(accumulate(sorted(arr)))
        return bisect(arr, 5000)