C++ || sliding window approach || beats 100%
\n# Code\n\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        int l = 0, r = 0, n = nums.size();\n        long lo
\n# Code\n```\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        int l = 0, r = 0, n = nums.size();\n        long long ans = 0;\n        \n        while(r < n) {\n            if (l != r && nums[r] == nums[r-1]) \n                l = r;\n            ans += r - l + 1;\n            r++;\n        }\n        \n        return ans;\n    }\n};\n```
['Two Pointers', 'Sliding Window', 'C++']