Evaluate n(n + 1)/2 for each non repeating subarray
Intuition\n- Each set of equal value divide the array into two separate array\n- On each non repeating subarray of size n, then the total number of subarrays po
# Intuition\n- Each set of equal value divide the array into two separate array\n- On each non repeating subarray of size n, then the total number of subarrays possible = n(n+1)/2\n- But in the solution, in place of calculating n(n + 1)/2, we can iterate and add all numbers from 1 to n that is equal to n(n+1)/2\n\n# Approach \n- Iterate over each item in nums\n- When ever found nums[i] equal to last value then reset the counter\n- Add the counter value to answer on each iteration\n\n# Code\n```\nlong long countAlternatingSubarrays(vector<int>& nums) {\n    long long ans = 0;\n    for(int i = 0, count = 1; i < nums.size(); ++i, count++){\n        if(i > 0 && nums[i] == nums[i-1]) count = 1;\n        ans += count;\n    }\n    return ans;\n}\n```\n\n---\n\n\n<b>Here is an article of my last interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon:\nhttps://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted\n\n---\n
['C++']