Best Approach using sorting | JAVA | TC: O(nlogn) SC: O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \nGroup all the positive numbers together and negative numbers.\nSorting helps to do that
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGroup all the positive numbers together and negative numbers.\nSorting helps to do that.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLet\'s say the given arrray is [-1 2 3 -2 -3 -1]. You can group all the positive and negative numbers together without sorting it (using two pointer). But, it might gives minimum prefix sum for some cases. \n\nEg:Grouping +ve and -ve numbers in the [-1 2 3 -2 -3 -1]\n-> *+ve numbers on left and -ve numbers on right side. \n    **[2 3 -1 -2 -3 -1]**, Here the array is not sorted. If you take prefix sum, then the resultant array will looks like **[2 5 4 2 -1 -2]**. The number of +ve elements are ***4****.\n\nCan we increase the positive elements count from 4?\n\n-> Sort the [-1 2 3 -2 -3 -1], Sorted array= [-3 -2 -1 -1 2 3]. \n   now take the suffix sum of the sorted array, you will get **[-2 1 3 4 5 3]**, the +ve element count is increased from 4 to 5. The O/P is 5.\n\nInstead of taking suffix sum, use the carry forward technique.\n  \n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> O(nlogn)+O(n) => O(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\nclass Solution {\n    public int maxScore(int[] nums) {\n  \n        Arrays.sort(nums);\n\n        int n=nums.length;\n        \n        int count=0;\n        long sum=0;\n\n        for(int i=n-1; i>=0; i--){\n            sum = sum+nums[i];\n            if(sum>0) count++;\n            else break;\n        }\n        \n        return count;\n        \n    }\n}\n```
['Array', 'Suffix Array', 'Sorting', 'Counting', 'Java']