Counting pattern
IntuitionApproach
Increase and reset to be changed when the condition is met.
Complexity
Time complexity:
O(n)
Space complexity:
O(1)Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

- Increase and reset to be changed when the condition is met.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)

# Code
```cpp []
class Solution {
public:
    long long countAlternatingSubarrays(vector<int>& nums) {
        // counting method 

        long long result =1, size = 1;

        for(int i=1;i<nums.size();i++){
            if(nums[i-1] != nums[i]){
                size++;
            }else{
                size =1;
            }
            result +=size;
        }
        return result;
    }
};
```
['C++']