O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n#define ll long long\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        long long int ans = 0;\n        int n = nums.size();\n        long long int cnt = 1;\n        for (int i = 1; i < n; i++) {\n            if (nums[i] != nums[i - 1]) {\n                cnt++;\n            } else {\n                ans = ans + (cnt * (cnt + 1)) / 2;\n                cnt = 1;\n            }\n        }\n        ans = ans + (cnt * (cnt + 1)) / 2;\n        return ans;\n    }\n};\n```
['C++']