Company: Visa_3Dec
Difficulty: medium
Count Sawtooth Subarrays Problem Description A sawtooth sequence is one where parity flips at every step - even and odd alternate all the way through, so each entry differs in parity from both of its neighbors. For example: [0, 1, 10, 7, 2] is a sawtooth sequence. (even, odd, even, odd, even) [9, 4, 3, 14] is a sawtooth sequence. (odd, even, odd, even) [2, 3, 5, 8, 7, 1] is not a sawtooth sequence because 3 and 5 are both odd. [7, 8, 2, 13] is not a sawtooth sequence because 8 and 2 are both even. Given an array of integers arr , count how many contiguous subarrays qualify as sawtooth sequences. A subarray consisting of a single element always counts as one. Examples Example 1: Input: arr = [1, 3, 5, 7, 9] Output: 5 Explanation: Every element here is odd, so no subarray of length 2 or more can alternate parity. That leaves the 5 single-element subarrays: [1], [3], [5], [7], [9]. Example 2: Input: arr = [1, 2, 1, 2, 1] Output: 15 Explanation: Parity alternates the whole way through, so