SIMPLE SLIDING WINDOW SOLUTION
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& num
# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        long long ans = 0;\n        int prev = -1;\n        int j = 0;\n        for(int i = 0;i<nums.size();i++){\n            if(nums[i]==prev){\n                j = i;\n            }\n            ans+=(i-j+1);\n            prev = nums[i];\n        }\n        return ans;\n    }\n};\n```
['Sliding Window', 'C++']