Sort | Easy C++ Solution
Intuition\nFor maximum no of prefixes to be positive :-\n- Large positive numbers should be at beginning(if any).\n- If Positive numbers are absent , then no po
# Intuition\nFor maximum no of prefixes to be positive :-\n- Large positive numbers should be at beginning(if any).\n- If Positive numbers are absent , then no positive prefix exist.\n\n# Approach\n- Check if any postive number is present in vector, if not return 0.\n- Sort the vector in descending order and find the prefix sum of the vector.Increase the variable if prefix sum is positive.\n\n# Complexity\n- Time complexity: $$O(nlogn)$$ \n\n- Space complexity: $$O(n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int maxScore(vector<int>& nums) {\n        int n = nums.size();\n        int cnt = 0;\n        for(int i=0;i<n;i++){\n            if(nums[i] > 0) cnt++;\n        }\n        if(!cnt) return 0;\n        sort(nums.begin(),nums.end(),greater<int>());\n        vector<long long> prefix;\n        long long sum = 0;\n        for(int i=0;i<n;i++){\n            sum += nums[i];\n            prefix.push_back(sum);\n        }\n        cnt = 0;\n        for(int i=0;i<n;i++){\n            if(prefix[i] > 0) cnt++;\n        }\n        return cnt;\n    }\n};\n```
['C++']