How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
Difficulty: Easy
Topics: Arrays
Companies: Premium
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:
nums[i] > 0
i and move nums[i] steps to the right in the circular array.result[i] to the value at the index where you land.nums[i] < 0
i and move abs(nums[i]) steps to the left in the circular array.result[i] to the value at the index where you land.nums[i] == 0
result[i] to nums[i].Input
nums = [3, -2, 1, 1]
Output
[1, 1, 1, 3]
Explanation
nums[0] = 3: move 3 steps right → reach nums[3] → result[0] = 1nums[1] = -2: move 2 steps left → reach nums[3] → result[1] = 1nums[2] = 1: move 1 step right → reach nums[3] → result[2] = 1nums[3] = 1: move 1 step right → reach nums[0] → result[3] = 3Input
nums = [-1, 4, -1]
Output
[-1, -1, 4]
Explanation
nums[0] = -1: move 1 step left → reach nums[2] → result[0] = -1nums[1] = 4: move 4 steps right → reach nums[2] → result[1] = -1nums[2] = -1: move 1 step left → reach nums[1] → result[2] = 41 <= nums.length <= 100-100 <= nums[i] <= 100import java.util.Arrays;
public class Main {
public static void main(String[] args) {
// Hardcoded input
int[] nums = {3, -2, 1, 1};
int[] result = transformedArray(nums);
// Print result
System.out.println(Arrays.toString(result));
}
public static int[] transformedArray(int[] nums) {
int n = nums.length;
int[] result = new int[n];
for (int i = 0; i < n; i++) {
if (nums[i] == 0) {
result[i] = 0;
} else {
int move = nums[i];
int newIndex = (i + move) % n;
// Handle negative index
if (newIndex < 0) {
newIndex += n;
}
result[i] = nums[newIndex];
}
}
return result;
}
}
— Written by Saurabh Patil • B.Tech CSE • Software Developer🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.