Scala two pointer stuff with recursion
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```scala []\nobject Solution {\n    def countAlternatingSubarrays(nums: Array[Int]): Long = {\n    def go(currentSubArrayLength: Int, prevElem: Int, x: Int, y: Int, nums: Array[Int], count: Long): Long = {\n       if (y == nums.length - 1) {\n         if (nums(y) != prevElem) count + calculateSubArrays(currentSubArrayLength + 1)\n         else if (currentSubArrayLength > 1) count + calculateSubArrays(currentSubArrayLength)\n         else count\n       }\n       else (prevElem, y) match {\n         case (p, ind) if nums(ind) != p => go(currentSubArrayLength + 1, nums(ind), x, y + 1, nums, count)\n         case (p, ind) if nums(ind) == p => go(1, nums(ind), y, y + 1, nums, count + calculateSubArrays(currentSubArrayLength))\n       }\n    }\n\n    def calculateSubArrays(length: Int): Long = length.toLong * (length.toLong - 1) / 2\n\n    if (nums.length == 1) 1L\n    else go(1, nums(0), 0, 1, nums, nums.length)\n    \n  }\n}\n```
['Scala']