{ "id": 3651, "name": "transformed_array", "difficulty": "Easy", "link": "https://leetcode.com/problems/transformed-array/", "date": "2024-12-01 00:00:00", "task_description": "You are given an integer array `nums` that represents a circular array. Your task is to create a new array `result` of the **same** size, following these rules: For each index `i` (where `0 <= i < nums.length`), perform the following **independent** actions: If `nums[i] > 0`: Start at index `i` and move `nums[i]` steps to the **right** in the circular array. Set `result[i]` to the value of the index where you land. If `nums[i] < 0`: Start at index `i` and move `abs(nums[i])` steps to the **left** in the circular array. Set `result[i]` to the value of the index where you land. If `nums[i] == 0`: Set `result[i]` to `nums[i]`. Return the new array `result`. **Note:** Since `nums` is circular, moving past the last element wraps around to the beginning, and moving before the first element wraps back to the end. **Example 1:** **Input:** nums = [3,-2,1,1] **Output:** [1,1,1,3] **Explanation:** For `nums[0]` that is equal to 3, If we move 3 steps to right, we reach `nums[3]`. So `result[0]` should be 1. For `nums[1]` that is equal to -2, If we move 2 steps to left, we reach `nums[3]`. So `result[1]` should be 1. For `nums[2]` that is equal to 1, If we move 1 step to right, we reach `nums[3]`. So `result[2]` should be 1. For `nums[3]` that is equal to 1, If we move 1 step to right, we reach `nums[0]`. So `result[3]` should be 3. **Example 2:** **Input:** nums = [-1,4,-1] **Output:** [-1,-1,4] **Explanation:** For `nums[0]` that is equal to -1, If we move 1 step to left, we reach `nums[2]`. So `result[0]` should be -1. For `nums[1]` that is equal to 4, If we move 4 steps to right, we reach `nums[2]`. So `result[1]` should be -1. For `nums[2]` that is equal to -1, If we move 1 step to left, we reach `nums[1]`. So `result[2]` should be 4. **Constraints:** `1 <= nums.length <= 100` `-100 <= nums[i] <= 100`", "public_test_cases": [ { "label": "Example 1", "input": "nums = [3,-2,1,1]", "output": "[1,1,1,3] " }, { "label": "Example 2", "input": "nums = [-1,4,-1]", "output": "[-1,-1,4] " } ], "private_test_cases": [ { "input": [ 20, -26, 14, -18, -48, 74, 0, -26, -55, -82, 19, -55, 1, -93, -62, -31, -49, -20, 25, 84, -33, -75, 59, 64, -7, 5, -20, -89, 3, 27, 4, -57, 25, -38, -94, -15, -92, 75, -43, 60, -74, -33, -35, -22, -5, -10, 24, 80, -73, 67, -92, 58, 9, -31, 30, -56, -78 ], "output": [ -33, 25, -49, -35, -93, 59, 0, -43, 19, -33, 27, -93, -93, -94, -82, -33, -7, 30, -22, 24, -5, -18, -7, 4, -20, 4, 0, 9, -57, -78, -94, -57, 20, 9, 30, -33, -26, -56, 9, -35, 64, -55, -26, -75, 60, -15, -93, -93, 25, 14, -31, 9, -48, 59, -89, -78, -15 ] }, { "input": [ -23, 42, 69, -97, -58, 97, -47, 65, 45, -93, 31, -44, -78, -49, 81, 60, 51, -80, -74, 87, 20, 1, 86, -32, -80, 58, -23, 6, -92, 9, -99, -11, 44, 71, 56, 50, 6, -64, -61 ], "output": [ 51, -58, 44, -32, -80, -80, -64, 71, 81, 71, 69, -47, -78, -97, -80, 6, -92, 60, 86, -92, 42, 86, -99, -99, 86, 97, -97, 71, 81, -61, -93, 20, -64, -23, -78, 65, -97, -78, 51 ] }, { "input": [ 61, -63, -16, 10, -39, -16, -95, -44, -16, 21, 4, 18, -56, 53, 39, 69, 29, -87, 43, -75, -81, -3, -66, -18, -73, 38, 9, 75, -98, 43, 67, -49, 100, -9, 62, 32, -13, -2, -81, 79, 88, -1, 16, 27, 81, -90, -88, 15, 60, 33, -20, -12, 86, 20, 83, 10, -55, 88, 82, 32, 98, 7, -66, 60, 54, 50, -42, -99, 69, -29, -98, -51, -54, 65, -63, -16, 11, -82 ], "output": [ 7, 29, 54, 53, 27, -99, -99, -1, -98, 67, 39, 43, 62, -42, 20, -95, -90, -16, 7, -66, -87, 43, 62, -16, 43, 60, 32, -73, -16, -54, -75, 98, 83, -73, 43, -99, -18, 32, 32, 88, -20, 88, 82, -98, 15, -9, -13, -66, 67, -39, 67, 79, 98, 65, 32, 50, -63, -99, -66, 53, -16, 69, -63, -90, 88, -2, -73, -88, 32, 88, -20, -81, 43, 98, 18, 32, 21, 65 ] }, { "input": [ 55, -64, -7, -6, -30, -37, 16, 58, 57, 33, 62, 82, -6, 94, 65, 0, -74, -32, 50, 70, -85, 55, 43, -70, 38, 75, 98, 86, -79, 41, -80, 65, 68, -17, -15, -92, 84, 5, -93, -8, -10, 32, 46, 40 ], "output": [ 82, 75, -8, 32, 50, -6, 43, 55, 55, 46, -79, -37, 16, 70, -92, 0, -80, 41, 38, -64, -70, 68, 55, 32, 50, -6, 84, 75, 5, 98, -93, 57, -6, -74, 70, 65, 68, 46, -17, 65, -80, 41, 55, -8 ] }, { "input": [ 1, -93, 55, -75, 27, 83, 4, 93, -63, 60, 89, 46, 7, 5, -67, -62, -49, -18, 77, 2, 44, 48, 76, -58, 99, 92, -2, -99, -35, -32, -61, -26, 49, 95, -69 ], "output": [ -93, 5, 76, 95, -26, 77, 89, -61, -62, -69, -32, 76, 2, 77, -18, -58, 55, -69, 92, 48, -32, -69, -35, 1, 77, 7, 99, 95, -35, 49, 27, 83, 46, -58, 1 ] } ], "haskell_template": "constructTransformedArray :: [Int] -> [Int]\nconstructTransformedArray nums ", "ocaml_template": "let constructTransformedArray (nums: int list) : int list = ", "scala_template": "def constructTransformedArray(nums: List[Int]): List[Int] = { \n \n}", "java_template": "class Solution {\n public int[] constructTransformedArray(int[] nums) {\n \n }\n}", "python_template": "class Solution(object):\n def constructTransformedArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n " }