1968. Array With Elements Not Equal to Average of Neighbors
https://leetcode.com/problems/array-with-elements-not-equal-to-average-of-neighbors
Description
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.
Example 1:
Example 2:
Constraints:
3 <= nums.length <= 105
0 <= nums[i] <= 105
ac
Previous1967. Number of Strings That Appear as Substrings in WordNext1969. Minimum Non-Zero Product of the Array Elements
Last updated