Tap here to switch tabs
Problem
Submissions

Problem: Sum of Beauty in the Array

med
30 min
Try to solve the Sum of Beauty in the Array problem.

Statement

Given a 00 indexed integer array nums, calculate the total sum of the beauty of nums[i] for all indices i satisfying 1≤1 \leq i ≤\leq nums.length −2- 2.

For each index i in the range 1≤1 \leq i ≤\leq nums.length −2- 2, the beauty of nums[i] is defined as:

  • 22, if for every index j with 0≤0 \leq j << i and every index k with i << k ≤\leq nums.length −1- 1, the condition nums[j] << nums[i] << nums[k] holds true.

  • 11, if the previous condition is not satisfied, but nums[i - 1] << nums[i] << nums[i + 1] holds true.

  • 00, if none of the above conditions hold true.

Return the sum of the beauty of nums[i] for all valid indices i.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sum of Beauty in the Array

med
30 min
Try to solve the Sum of Beauty in the Array problem.

Statement

Given a 00 indexed integer array nums, calculate the total sum of the beauty of nums[i] for all indices i satisfying 1≤1 \leq i ≤\leq nums.length −2- 2.

For each index i in the range 1≤1 \leq i ≤\leq nums.length −2- 2, the beauty of nums[i] is defined as:

  • 22, if for every index j with 0≤0 \leq j << i and every index k with i << k ≤\leq nums.length −1- 1, the condition nums[j] << nums[i] << nums[k] holds true.

  • 11, if the previous condition is not satisfied, but nums[i - 1] << nums[i] << nums[i + 1] holds true.

  • 00, if none of the above conditions hold true.

Return the sum of the beauty of nums[i] for all valid indices i.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5