Search
⌘K

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.

Comments

Your account is free and you can post anonymously if you choose.