Recursion, without memoization  Beats 6.15%
Approach\nI started from Top down DP, but it tuns out solution without  memoization accepted.\nwe\'re not actually counting subarrays, we can instead use the ar
# Approach\nI started from Top down DP, but it tuns out solution without  memoization accepted.\nwe\'re not actually counting subarrays, we can instead use the arithmetic progression formula 1+2+3+4+\u2026, which gives us the number of subarrays within the start and end indexes. Please refer to the comments in the code for more details.\n\n# Complexity\n- Time complexity:\n$$O(2^n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```javascript []\nvar countAlternatingSubarrays = function(nums) {\n    \n    const dfs=(start, i)=>{\n        if(i===nums.length) return 0;\n\n        let ans=0;\n        if(i>0 && nums[i-1]!==nums[i]){\n            // extending a widow\n            // (i-start+1) - add all subarrays within a range, \n            // e.g 1,0,1,0,1 = 1+2+3+4+5\n            ans+=dfs(start,i+1)+(i-start+1);\n        }else{\n            // if we can not extend, start new window\n            ans+=dfs(i,i+1)+1;\n        }\n\n        return ans;\n    }\n\n    return dfs(0,0);\n};\n```
['JavaScript']