Practice Array With Elements Not Equal to Average of Neighbors
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a 0-indexed array nums of distinct integers. You want to rearrange the elements in the array such that every element in the rearranged array is not equal to the average of its neighbors. More formally, the rearranged array should have the property such that for every i in the range 1 <= i < nums.length - 1, (nums[i-1] + nums[i+1]) / 2 is not equal to nums[i]. Return any rearrangement of nums that meets the requirements.
Source: Array With Elements Not Equal to Average of Neighbors on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3,4,5]
[1,2,4,5,3]
# Example 2
nums = [6,2,0,9,7]
[9,7,6,2,0]
Constraints
Related LeetCode Problems
Practice more problems similar to Array With Elements Not Equal to Average of Neighbors.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.