Back to course home
0% completed
Vote For New Content
Solution: Number of Valid Subarrays
Problem Statement
Given an integer array nums
, return the total count
of non-empty
subarrays within nums
where each subarray must have its first element
as the smallest
among all its elements.
A subarray
is a Contiguous
part of an array.
Examples
-
Example 1:
- Input:
nums = [4, 3, 1]
- Expected Output:
3
- Justification: The valid subarrays are
[4]
,[3]
, and[1]
. Each subarray consists of a single element, satisfying the condition since there's no smaller element than the first.
- Input:
-
Example 2:
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page