625. Number of Valid Subarrays
Given an integer array nums, return the number of non-empty subarrays with the leftmost element of the subarray not larger than other elements in the subarray.
A subarray is a contiguous part of an array.
Example 1:
Input: nums = [2,5,3,6,4]
Output: 11
Explanation: There are 11 valid subarrays: [2],[5],[3],[6],[4],[2,5],[3,6],[2,5,3],[3,6,4],[2,5,3,6],[2,5,3,6,4].
Example 2:
Input: nums = [6,5,4]
Output: 3
Explanation: The 3 valid subarrays are: [6],[5],[4].
Now Your Turn!
Pick the correct output for the given inputInput: [4,5,3,2,6]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 5 * 104
- 0 <= nums[i] <= 105