Company: Autodesk Apprentice Software engineer_21april
Difficulty: medium
A sawtooth sequence is a sequence of numbers that alternate between even and odd. In other words, each element is of different parity than both of its neighboring elements. Examples of sawtooth sequences: 0 1 10 7 2 9 4 3 14 Examples of sequences that are not sawtooth sequences: 2 3 5 8 7 1 (3 and 5 are both odd; 7 and 1 are both odd) 7 8 2 13 (8 and 2 are both even) Given an array of integers arr , your task is to count the number of contiguous subarrays that represent a sawtooth sequence of at least one element. Example For arr = [1, 3, 5, 7, 9] , the output should be solution(arr) = 5 . Since all the elements are odd, it won't be possible to form any sawtooth subarrays of length 2 or more. There are 5 possible subarrays containing one element, so the answer is 5. For arr = [1, 2, 1, 2, 1] , the output should be solution(arr) = 15 . All contiguous subarrays satisfy the condition of alternating parity. There are 15 possible contiguous subarrays, so the answer is 15. For arr = [1, 2, 3