← 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 794 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.
  • Customer Success Executive

    Remote

  • CRM Senior Solution Sales Executive

    Brasilia, Brasilia, Brazil

  • CPQ Senior Solution Sales Executive

    Sao Paulo, SAO PAULO, Brazil

Or practice this question first

Next question