Java | Standard sliding window | time: O(n) | space: O(1)
 # Intuition  \n\n\n\n\n\n# Complexity\n- Time complexity: O(n)\n\n\n- Space complexity: O(1)\n\n\n# Code\n\nclass Solution {\n    public long countAlternatingS
<!-- # 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<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        long result = 0;\n        \n        int end = 0;\n        int start = 0;\n        while(end < nums.length) {\n            if(end == 0)\n                result++;\n            else {\n                while(end < nums.length && nums[end] != nums[end - 1]) {\n                    end++;\n                    result += end - start;\n                }\n                \n                if(end != nums.length) {\n                    result++;\n                    start = end;\n                }\n            }\n            end++;\n        }\n        \n        return result;\n    }\n}\n```
['Two Pointers', 'Sliding Window', 'Java']