Ctrl K

Counting Rising Stretches

Medium
You get an array of positive integers values. Return how many contiguous pieces (subarrays) it has in which every element is strictly greater than the one before it. A piece of a single element counts as rising too.
Example 1
values=[2, 5, 7, 7, 3, 4] → 10

There are six pieces of length 1; the rising pieces of length 2 are [2, 5], [5, 7], [3, 4]; of length 3, [2, 5, 7]. That makes 10.

Example 2
values=[9, 8, 7] → 3

The array only goes down, so only the single elements count.

Example 3
values=[1, 2, 3, 4] → 10
Constraints
  • 1 ≤ len(values) ≤ 10⁵
  • 1 ≤ values[i] ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNth Number Built From Given Primes MediumChain of Multiples MediumBest Rotation for a Weighted Sum MediumDuel for the End Cards MediumBiggest Division Chain Medium
loading Python…
Input
values=[2, 5, 7, 7, 3, 4]
Expected
10

Run checks the first 3 tests in your browser. Submit checks all 129 tests on the server, hidden ones included.