1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
Input: nums = [1,4,3,3,2]
Output: 6
Explanation:
There are 6 subarrays which have the first and the last elements equal to the
largest element of the subarray:
* subarray `[**_1_** ,4,3,3,2]`, with its largest element 1. The first element is 1 and the last element is also 1.
* subarray `[1,_**4**_ ,3,3,2]`, with its largest element 4. The first element is 4 and the last element is also 4.
* subarray `[1,4,_**3**_ ,3,2]`, with its largest element 3. The first element is 3 and the last element is also 3.
* subarray `[1,4,3,_**3**_ ,2]`, with its largest element 3. The first element is 3 and the last element is also 3.
* subarray `[1,4,3,3,_**2**_]`, with its largest element 2. The first element is 2 and the last element is also 2.
* subarray `[1,4,_**3,3**_ ,2]`, with its largest element 3. The first element is 3 and the last element is also 3.
Hence, we return 6.
|