PIXELBANKv9.1.0
Menu

Given an integer array nums, rotate the array to the right by k steps.

Output the rotated array as space-separated integers.

Example:

Input:
1,2,3,4,5,6,7
3
Output:
5 6 7 1 2 3 4
Reasoning:
  • The input array is 1,2,3,4,5,6,71, 2, 3, 4, 5, 6, 7 and we need to rotate it to the right by k=3k = 3 steps.
  • To rotate the array, we split it into two parts: the last kk elements (5,6,75, 6, 7) and the rest of the array (1,2,3,41, 2, 3, 4).
  • We then concatenate these two parts in reverse order, resulting in the rotated array: 5,6,7,1,2,3,45, 6, 7, 1, 2, 3, 4.
  • The final output is the rotated array as space-separated integers: 56712345 6 7 1 2 3 4.

Constraints:

  • 1 <= len(nums) <= 10^5
  • -2^31 <= nums[i] <= 2^31 - 1
  • 0 <= k <= 10^5
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.