Count Strictly Increasing Subarrays - Problem
Count Strictly Increasing Subarrays is a fascinating problem that tests your ability to identify patterns in array sequences.

Given an array nums consisting of positive integers, you need to count how many subarrays are in strictly increasing order. A subarray is a contiguous part of an array, and strictly increasing means each element must be greater than the previous one (not equal).

For example, in the array [1, 3, 2, 4, 5]:
[1], [3], [2], [4], [5] are all strictly increasing (single elements)
[1, 3] is strictly increasing
[2, 4], [4, 5], [2, 4, 5] are strictly increasing
• But [3, 2] is not (decreasing)

Your task: Return the total count of all strictly increasing subarrays in the given array.

Input & Output

example_1.py — Basic Case
$ Input: [1, 3, 2, 4, 5]
Output: 9
💡 Note: The strictly increasing subarrays are: [1], [3], [2], [4], [5], [1,3], [2,4], [4,5], [2,4,5]. Total count = 9.
example_2.py — Monotonic Increasing
$ Input: [1, 2, 3, 4]
Output: 10
💡 Note: All subarrays are strictly increasing: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], [1,2,3,4]. Total = 4*5/2 = 10.
example_3.py — Single Element
$ Input: [5]
Output: 1
💡 Note: Only one subarray exists: [5], which is trivially strictly increasing. Count = 1.

Constraints

  • 1 ≤ nums.length ≤ 105
  • 1 ≤ nums[i] ≤ 106
  • All elements are positive integers

Visualization

Tap to expand
Mountain Climbing Route Analysis13245Segment 1: [1→3]Length = 2Routes = 2×3/2 = 3Segment 2: [2→4→5]Length = 3Routes = 3×4/2 = 6Total Routes: 3 + 6 = 9 different ascending paths!Route Details:Segment 1 routes:[1], [3], [1,3]Segment 2 routes:[2], [4], [5],[2,4], [4,5], [2,4,5]
Understanding the Visualization
1
Identify Climbing Segments
Find all consecutive ascending segments in your route
2
Count Routes per Segment
For each ascending segment of length n, you can create n*(n+1)/2 different climbing routes
3
Sum All Possibilities
Add up the route counts from all ascending segments to get the total
Key Takeaway
🎯 Key Insight: When you find a sequence of n consecutive ascending elevations, you automatically get n*(n+1)/2 different climbing routes within that segment. Count all segments and sum their contributions for the optimal O(n) solution!
Asked in
Google 45 Amazon 38 Meta 32 Microsoft 28
42.0K Views
High Frequency
~15 min Avg. Time
1.9K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen