Simple JAVA Solution || 10 lines
Approach\nWe can follow the Greedy approach, and sort the array. Then we will find the sum of elements till it becomes negative and the index before that will b
# Approach\nWe can follow the Greedy approach, and sort the array. Then we will find the sum of elements till it becomes negative and the index before that will be our answer.\n\n# Complexity\n- Time complexity: O(n logn)\n- Space complexity: O(1)\n\n# Code\n```\npublic int maxScore(int[] nums) {\n    Arrays.sort(nums);\n    long sum = 0;\n    for(int i = nums.length - 1; i >= 0; i--) {\n        sum += nums[i];\n        if(sum <= 0)\n            return nums.length - i - 1;\n    }\n    return nums.length;\n}\n```\nPlease upvote, if you found it useful.
['Greedy', 'Sorting', 'Java']