Leetcode 2085 Solution
This article provides solution to leetcode question 2085 (array-with-elements-not-equal-to-average-of-neighbors)
Access this page by simply typing in "lcs 2085" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/array-with-elements-not-equal-to-average-of-neighbors
Solution
class Solution:
def rearrangeArray(self, nums: List[int]) -> List[int]:
nums.sort()
ans = []
l = 0
r = len(nums) - 1
while len(ans) < len(nums):
ans.append(nums[l])
l += 1
if r >= l:
ans.append(nums[r])
r -= 1
return ans