3651. Transformed Array
My accepted Python solution to LeetCode problem 3651, Transformed Array, running in 54ms.
- Difficulty: Easy
- Python
- Runtime 54ms
- Memory 17.3MB
- 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 54ms, memory 17.3MB, accepted 2025-12-31.
class Solution:
def constructTransformedArray(self, nums: List[int]) -> List[int]:
n = len(nums)
result = [0] * n
for i in range(n):
if nums[i] > 0:
# Move right
new_idx = (i + nums[i]) % n
result[i] = nums[new_idx]
elif nums[i] < 0:
# Move left
new_idx = (i + nums[i]) % n
result[i] = nums[new_idx]
else:
result[i] = nums[i]
return result