Count Strictly Increasing Subarrays - Golang

Problem statement:

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.

Example:

Input:

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

Expected output:

10

Explanation: The strictly increasing subarrays are the following:

  • Subarrays of length 1: [1], [3], [5], [4], [4], [6].
  • Subarrays of length 2: [1,3], [3,5], [4,6].
  • Subarrays of length 3: [1,3,5].

The total number of subarrays is 6 + 3 + 1 = 10.

If you would like to solve the problem on Leetcode, here is the link to the problem: https://leetcode.com/problems/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
}