Easy C++ Solution
```\nlong long countAlternatingSubarrays(vector& nums) {\n        long long ans=0;\n        int n=nums.size();\n        int i=0,j=0;\n        while(j0&&nums[j]!
```\nlong long countAlternatingSubarrays(vector<int>& nums) {\n        long long ans=0;\n        int n=nums.size();\n        int i=0,j=0;\n        while(j<n)\n        {\n            if(i==j||(j>0&&nums[j]!=nums[j-1]))\n            {\n                ans+=(j-i+1);\n                j++;\n            }\n            else \n               {\n                   i=j;\n               }\n        }\n        return ans;\n    }
[]