Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 2012. Sum of Beauty in the Array
For each interior element, determine whether it's greater than all previous elements and smaller than all following elements (beauty 2), else whether it is strictly between its immediate neighbors (beauty 1), otherwise 0; sum these values. The key is using prefix maxima and suffix minima (linear-time, O(n) space or O(1) extra) to handle up to n = 1e5 efficiently.
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.