Brute Completion Challenge #4 (no analysis)
Code\nruby []\n# @param {Integer[]} nums\n# @return {Integer}\ndef count_alternating_subarrays(nums)\n    # every length 1 subarray is alternating:\n    l = num
# Code\n```ruby []\n# @param {Integer[]} nums\n# @return {Integer}\ndef count_alternating_subarrays(nums)\n    # every length 1 subarray is alternating:\n    l = nums.length\n    # all length = 1 subarrays are valid\n    altsubs = l\n    # start with a length = 2 subarray\n    ic = 1\n    is = 0\n    # there is no current longest valid subarray\n    curr_longest_sub = []\n    # iterate thru all possible LONGEST arrays, we can compute how many\n    # subarrays each conatains with a simple equation\n    while ic < l\n        # since we jump bad subarrays, we only ever need to check\n        # the last two values\n        if nums[ic] != nums[ic - 1]\n            curr_longest_sub = nums[is..ic]\n            ic += 1\n            #puts "replacing subarray #{subarr.inspect}"\n        else\n            # jump over the bad subarray\n            is = ic\n            ic += 1\n            len = curr_longest_sub.length\n            # the number of valid length == 2 subarrays in any array of length\n            # >= 2 is given by the equation below:\n            altsubs += (((len - 1) * len)/2)\n            curr_longest_sub = []\n        end\n    end\n    # check if there was still a valid sub when the\n    # while loop reached the end\n    if not curr_longest_sub.empty?\n        len = curr_longest_sub.length\n        remainder = (((len - 1) * len)/2)\n        altsubs += remainder\n    end\n    return altsubs\nend\n```
['Ruby']