Sliding (Destructive) Window
Intuition\nWindow is broken when adjacent nums are not alternating. So set left of window to right.\n\n# Code\n\nclass Solution:\n    def countAlternatingSubarr
# Intuition\nWindow is broken when adjacent nums are not alternating. So set left of window to right.\n\n# Code\n```\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n        # Sliding (Destructive) Window\n        # Time Complexity: O(n)\n        # Space Complexity: O(n)\n        ans, i = 1, 0\n        for j in range(1, len(nums)):\n            if nums[j] ^ 1 != nums[j-1]:\n                i = j\n            ans += j - i + 1\n        return ans\n```
['Python3']