3379. Transformed Array Easy

@problem@discussion
#Array#Simulation



1/**
2 * [3379] Transformed Array
3 *
4 * 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:
5 * For each index i (where 0 <= i < nums.length), perform the following independent actions:
6 * 
7 * 	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.
8 * 	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.
9 * 	If nums[i] == 0: Set result[i] to nums[i].
10 * 
11 * Return the new array result.
12 * 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.
13 *  
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [3,-2,1,1]</span>
17 * Output: <span class="example-io">[1,1,1,3]</span>
18 * Explanation:
19 * 
20 * 	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.
21 * 	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.
22 * 	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.
23 * 	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.
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: <span class="example-io">nums = [-1,4,-1]</span>
28 * Output: <span class="example-io">[-1,-1,4]</span>
29 * Explanation:
30 * 
31 * 	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.
32 * 	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.
33 * 	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.
34 * </div>
35 *  
36 * Constraints:
37 * 
38 * 	1 <= nums.length <= 100
39 * 	-100 <= nums[i] <= 100
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/transformed-array/
45// discuss: https://leetcode.com/problems/transformed-array/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn construct_transformed_array(nums: Vec<i32>) -> Vec<i32> {
51        vec![]
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_3379() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.