Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Rotate Array

Easy
arraytwo-pointersmath

Rotate the array nums to the right by k steps and return it.

Input

  • Line 1: space-separated integers nums
  • Line 2: integer k (k ≥ 0)

Output: the rotated array, space-separated.

Example 1
Input:
1 2 3 4 5 6 7
3
Output:
5 6 7 1 2 3 4
Example 2
Input:
-1 -100 3 99
2
Output:
3 99 -1 -100

Constraints

  • 1 ≤ nums.length ≤ 10^5
  • 0 ≤ k ≤ 10^5
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.