Best Easy Soln
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: O(n)\n\n\n- Space complexity: O(1)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        long long count = 0;\n\n        int n = nums.size();\n\n        for(int i =0; i < n; i++){\n            int j =i;\n\n            while(j+1 < n && nums[j] != nums[j+1]){ // Alternating\n                 j++;\n            } \n\n            int len = j - i + 1;\n\n            count += (long long) len*(len+1)/2;\n\n            i = j;\n\n        }\n          // T.C -> O(n)\n          //S.C -> O(1)\n        return count;\n    }\n};\n```
['C++']