Posted on

Description

Submission

class Solution {
public:
    int maxNumberOfApples(vector<int>& arr) {
        sort(arr.begin(), arr.end());
        
        int ret = 0;
        int sum = 0;
        for(int x: arr) {
            sum += x;
            if(sum > 5000) return ret;
            ret++;
        }
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *