Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
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.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.