Company: Cohesity
Difficulty: medium
Arithmetic Mean Neighbors You are given an array of integers a . Your task is to calculate how many numbers in the array are equal to the arithmetic mean of their immediate neighbors. In other words, count the number of indices i such that: a[i] = (a[i-1] + a[i+1]) / 2 Note: If a[i-1] or a[i+1] don\'t exist, they should be considered equal to 0. Input array.integer a An array of integers. Output integer The number of elements from a that are equal to the arithmetic mean of their neighbors. Constraints 1 ≤ a.length ≤ 10³ 0 ≤ a[i] ≤ 10⁶ Examples Example 1: Input: a = [2, 4, 6, 6, 3] Output: 3 There are 3 elements that satisfy the condition: a[0] = (0 + 4) / 2 a[1] = (2 + 6) / 2 a[4] = (6 + 0) / 2 Example 2: Input: a = [1, 3, 2] Output: 0 Neither of the numbers satisfies the condition. Execution Limits Time limit: 0.5 seconds (cpp) Memory limit: 1 GB