Count Strictly Increasing Subarrays - Problem
You are given an array nums consisting of positive integers. Return the number of subarrays of nums that are in strictly increasing order.
A subarray is a contiguous part of an array. A sequence is strictly increasing if each element is greater than the previous element.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,3,2,4,5]
›
Output:
8
💡 Note:
Strictly increasing subarrays: [1], [3], [2], [4], [5], [1,3], [2,4], [4,5], [2,4,5] = 8 total
Example 2 — All Increasing
$
Input:
nums = [1,2,3,4]
›
Output:
10
💡 Note:
All subarrays are increasing: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], [1,2,3,4] = 10 total
Example 3 — Single Element
$
Input:
nums = [5]
›
Output:
1
💡 Note:
Only one subarray [5], which is trivially increasing
Constraints
- 1 ≤ nums.length ≤ 1000
- 1 ≤ nums[i] ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Given array [1,3,2,4,5]
2
Find Sequences
Identify increasing sequences: [1,3] and [2,4,5]
3
Count Subarrays
Each sequence contributes multiple valid subarrays
Key Takeaway
🎯 Key Insight: Use the formula length×(length+1)/2 to count subarrays from each increasing sequence
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code