Easy -  Linear time and constant space
Intuition\n Describe your first thoughts on how to solve this problem. \nTo count the number of alternating subarrays in the given list of numbers, we can itera
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo count the number of alternating subarrays in the given list of numbers, we can iterate through the list while maintaining a count of consecutive alternating elements. Whenever we encounter a non-alternating element, we calculate the number of subarrays that can be formed using the current count and add it to the result. Finally, we return the total count of alternating subarrays.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n- We iterate through the list, keeping track of the count of consecutive alternating elements.\n- Whenever we encounter a non-alternating element, we calculate the number of subarrays that can be formed using the current count and add it to the result.\n- The total count of alternating subarrays is the sum of all such counts calculated for each non-alternating element encountered.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of this approach is O(n), where n is the    length of the input list. We iterate through the list once to calculate the count of alternating subarrays.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity is O(1) since we are using only a constant amount of extra space for storing variables regardless of the size of the input list.\n# Code\n```\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n        count = 1\n        result = 0\n        for i in range(1, len(nums)):\n            if nums[i] != nums[i - 1]:\n                count += 1\n            else:\n                result += count * (count + 1) // 2\n                count = 1\n        result += count * (count + 1) // 2\n        return result\n\n```\n![images.jpeg](https://assets.leetcode.com/users/images/97802d86-c269-4f04-b1ec-9f8ba5f504fd_1711860184.9105036.jpeg)\n\n
['Python3']