Tap here to switch tabs
Problem
Submissions

Problem: Array With Elements Not Equal to Average of Neighbors

med
30 min
Try to solve the Array With Elements Not Equal to Average of Neighbors problem.

Statement

Given an array of integers nums, rearrange the elements such that for every index i where 1≤1 \leq i ≤\leq nums.length −2- 2, the value at nums[i] is not equal to the average of its immediate neighbors, nums[i - 1] and nums[i + 1].

Return any valid permutation of nums that satisfies this condition.

Note: If multiple valid arrangements exist, return any of them.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Array With Elements Not Equal to Average of Neighbors

med
30 min
Try to solve the Array With Elements Not Equal to Average of Neighbors problem.

Statement

Given an array of integers nums, rearrange the elements such that for every index i where 1≤1 \leq i ≤\leq nums.length −2- 2, the value at nums[i] is not equal to the average of its immediate neighbors, nums[i - 1] and nums[i + 1].

Return any valid permutation of nums that satisfies this condition.

Note: If multiple valid arrangements exist, return any of them.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤105\leq 10^5