Calculate Region
There is a straight line of students of various heights. The students' heights are given in the form of an array, in the order they are standing in the line.
Consider the region of a student as the length of the largest subarray that includes that student's position, and in which that student's height is equal to maximum height among all students present in that subarray. Return the sum of the region of all students.
Complete the function calculateTotalRegion in the editor.
calculateTotalRegion has the following parameter(s):
heights: an array of the heights of students standing in the lineReturns
long integer: the desired sum of all regions
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
- 1 ≤ length of heights ≤ 105
- 1 ≤ heights[i] ≤ 109