✅ c++ greedy | sorting | easy code with logic ✅
\n# Code\n\nclass Solution {\npublic:\n    /*app 1: greedy way ==> rearrange numbers in descending order.\n    T.c: O(N*logN)\n    \n    Intuition::\n    \n    
\n# Code\n```\nclass Solution {\npublic:\n    /*app 1: greedy way ==> rearrange numbers in descending order.\n    T.c: O(N*logN)\n    \n    Intuition::\n    \n    to get max. no. of +ve integers, we should have max. no. of positive numbers\n    in the beginning of array and then the negative numbers.\n    \n    bcos, doing so ensures that we have maximum possible +ve prefix sum.\n    It\'s like a greedy way of rearranging numbers.\n    \n    */\n    int maxScore(vector<int>& nums) {\n        int n=nums.size();\n        \n        vector<long long> prefix(n);\n        \n        //sort the array in desc order\n        sort(nums.begin(),nums.end(),greater<int>());\n        \n        prefix[0]=nums[0];\n        \n        int score=0;\n        if(prefix[0] > 0) score++;\n        \n        //count the no. of +ve numbers in prefix sum array\n        for(int i=1; i<n; i++){\n            prefix[i] = prefix[i-1] + nums[i];\n            \n            if(prefix[i] > 0) score++;\n        }\n        \n        return score;\n    }\n};\n```
['C++']