2283. Sort Even and Odd Indices Independently
My accepted Python solution to LeetCode problem 2283, Sort Even and Odd Indices Independently, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.5MB, accepted 2025-12-29.
class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
even = sorted(nums[::2]) # non-decreasing
odd = sorted(nums[1::2], reverse=True) # non-increasing
result = []
i, j = 0, 0
for k in range(len(nums)):
if k % 2 == 0:
result.append(even[i])
i += 1
else:
result.append(odd[j])
j += 1
return result