1
2
3
4
5
6
7
8
9
10
|
Input: nums = [4,3,1,2,4]
Output: 2
Explanation: There are 2 beautiful subarrays in nums: [4,_3,1,2_ ,4] and [_4,3,1,2,4_].
- We can make all elements in the subarray [3,1,2] equal to 0 in the following way:
- Choose [_3_ , 1, _2_] and k = 1. Subtract 21 from both numbers. The subarray becomes [1, 1, 0].
- Choose [_1_ , _1_ , 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 0, 0].
- We can make all elements in the subarray [4,3,1,2,4] equal to 0 in the following way:
- Choose [_4_ , 3, 1, 2, _4_] and k = 2. Subtract 22 from both numbers. The subarray becomes [0, 3, 1, 2, 0].
- Choose [0, _3_ , _1_ , 2, 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 2, 0, 2, 0].
- Choose [0, _2_ , 0, _2_ , 0] and k = 1. Subtract 21 from both numbers. The subarray becomes [0, 0, 0, 0, 0].
|