Simple Java Solution
Code\n\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        int l=0;\n        int r=0;\n        long ans = 0;\n        int p = -1
# Code\n```\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        int l=0;\n        int r=0;\n        long ans = 0;\n        int p = -1;\n        while(r<nums.length){\n            if(nums[r]==p){\n                l = r;\n            }\n            ans += r-l+1;\n            p =nums[r];\n            \n            r++;\n        }\n        return ans;\n    }\n}\n```
['Two Pointers', 'Sliding Window', 'Java']