O(N) time and easy simple solution.
Intuition\nCount number of continueous alternating number and all possible subarray that can be made using it. \n\n# Approach\nuse long to store the and take ca
# Intuition\nCount number of continueous alternating number and all possible subarray that can be made using it. \n\n# Approach\nuse long to store the and take care of overflow , count alternating 0 and 1 continueous if it break add answer to it and then at last add the last the left subarray. which i did after completing for loop.\n\n# Complexity\n- Time complexity:\nO(N)\n\n# Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        long long ans=0;\n        int count=1;\n        for(int i=1 ; i<nums.size(); i++)\n        {\n            if(nums[i]==nums[i-1])\n            {\n                ans+=(1ll*count*1ll*(count+1))/2;\n                count=1; // to start new counting of alternates\n            }\n            else{\n                count++;\n            }\n        }\n        ans+=(1ll*count*1ll*(count+1))/2;\n        return ans;\n    }\n};\n```
['Array', 'Math', 'C++']