Company: Visa__...
Difficulty: medium
Count Sawtooth Subarrays Problem Description 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. 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. For example: Valid Sawtooth: [0, 1, 10, 7, 2] (Even, Odd, Even, Odd, Even) Valid Sawtooth: [9, 4, 3, 14] (Odd, Even, Odd, Even) Invalid: [2, 3, 5, 8] (5 and 8 are valid neighbors, but 3 and 5 are both odd) Examples Example 1: Input: arr = [1, 3, 5, 7, 9] Output: 5 Explanation: 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. Example 2: Input: arr = [1, 2, 1, 2, 1] Output: 15 Explanation: All contiguous subarrays satisfy the condition of alternating parity. There are 15 possible contiguous sub