Leetcode 2640. Find the Score of All Prefixes of an Array
For each prefix nums[0..i], compute the score defined as the sum over j<=i of (nums[j] + max(nums[0..j])); the core task is to output these scores for all prefixes efficiently. Key insight: maintain a running prefix sum and the cumulative sum of prefix-maximums (which only changes when a new larger element appears) to produce all answers in O(n) for n up to 1e5.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.