easy solution using java check it out || <<AWSZOABI>>
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 
# 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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        long count = 0; // Initialize count\n        \n        if (nums.length == 0) {\n            return count; // Return 0 for empty array\n        }\n\n        count += nums.length; // Each element forms a subarray of length 1\n        int[] helper = new int[nums.length]; // Helper array to store alternating counts\n\n        for (int i = 1; i < nums.length; i++) {\n            if (nums[i] != nums[i - 1]) {\n                helper[i] = helper[i - 1] + 1; // Extend alternating subarray\n            }\n            count += helper[i]; // Add to total count\n        }\n\n        return count; // Return the total count\n    }\n}\n\n```
['Java']