The Array With Elements Not Equal to Average of Neighbors interview question asks you to reorder a given array such that for every index i (where 1 < i < n-1), the element nums[i] is not equal to the average of its immediate neighbors, (nums[i-1] + nums[i+1]) / 2. This Array With Elements Not Equal to Average of Neighbors coding problem is about breaking local patterns.
Uber and Microsoft use this to see if a candidate can find a clever constructive solution rather than trying every permutation. It tests "Wiggle" or "Zig-zag" logic—the idea that if you alternate between small and large values, a number can never be the average of its neighbors.
This follows the Array, Sorting, Greedy interview pattern. A robust way to solve this is to sort the array and then alternate between elements from the first half and the second half. This creates a "peak and valley" pattern where every element is either larger than both its neighbors or smaller than both.
Consider nums = [1, 2, 3, 4, 5].
Constructive problems often have a "sorting-based" shortcut. If you need to avoid a specific linear relationship between adjacent elements, try arranging them in a "high-low-high" or "zig-zag" order.