Back to problems

Maximum Positive Prefixes

Algorithm · SoFi · Medium

Requirements You are given an integer array. Permute its values so that as many entries as possible in the resulting prefix-sum sequence are strictly greater than zero. Your implementation must run in O(n log n) time. Implement the following function: Examples Explanation: Its prefix sums are [7, 11, 9, 4], so all four prefix totals are positive. Explanation: The accumulated sums become [3, 4, 2, -6], giving three strictly positive prefix sums. Constraints The input consists…

Checking your access…