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. [ even ] [ odd ] 0 1 10 7 2 ✓ 9 4 3 14 ✓ 2 3 5 8 7 1 ✗ 7 8 2 13 ✗ 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, 7, 6, 5] , the output should be solution(arr) = 12 . Only contiguous subarrays that don't include 3, 7 satisfy the condition of a