← All questions
MediumCoding

Sum of Beauty in the Array

Asked atServiceNow
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Clarify the beauty definition for each interior index.
  2. 02Precompute prefix maximum before each position and suffix minimum after it.
  3. 03Award two when the element lies strictly between those global bounds.
  4. 04Otherwise award one if it is strictly between immediate neighbors.

Reference answer

Then expect these follow-ups

  • Can one prefix array be avoided?

    Tests: space optimization

  • Why is local increasing not enough for two points?

    Tests: conditions

Hiring now

ServiceNow has 806 open roles right now

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Senior Software Engineer – Compute Engineering

    Santa Clara, CALIFORNIA, United States

  • Staff Software Engineer – Compute Engineering

    Santa Clara, CALIFORNIA, United States

  • Senior Staff Software Engineer – Compute Engineering

    Santa Clara, CALIFORNIA, United States

Or practice this question first

Next question