Easy Solution using Dynamic Programming concept
\n# Approach\n Describe your approach to solving the problem. \nDynamic Programming\nConcept is same but without array adding them up right away\n# Complexity\n
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nDynamic Programming\nConcept is same but without array adding them up right away\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunc countAlternatingSubarrays(nums []int) int64 {\n    var numberOfSubarrays int64\n    var prev int64\n    // prev is going to help to cal culate current subarrays len\n    // if condition met and adding it to counter\n    prev = 1\n    numberOfSubarrays = 1\n    for i := 1; i < len(nums); i++{\n        if nums[i] != nums[i-1] {\n            prev = prev + 1\n\n        }else{\n            prev = 1\n        }\n        numberOfSubarrays += prev\n    }\n\n\n    return numberOfSubarrays\n}\n```
['Array', 'Math', 'Dynamic Programming', 'Go']