Count Strictly Increasing Subarrays

Problem statement

nums contains positive integers. Count how many contiguous subarrays are strictly increasing (each next value larger than the previous). Single elements count.

Example:

Input:

[1, 3, 5, 4, 4, 6]

Expected output:

10

Why: six length-1 slices, three length-2 rising pairs, and one length-3 rising triple (1,3,5).

Practice on LeetCode: Count Strictly Increasing Subarrays

Golang Solution

func countSubarrays(nums []int) int64 {
    var totalCount, subarrayCount int64
    totalCount = 1
    subarrayCount = 1
    for i := 1; i < len(nums); i++ {
        if nums[i] > nums[i-1] {
            subarrayCount += 1
        } else {
            subarrayCount = 1
        }
        totalCount += subarrayCount
    }
    return totalCount
}