Rotate an Array by K

Problem Rotate an array to the right by k steps, in place with O(1) extra space.

Input / Output

  • Input: array nums, integer k (may exceed n).
  • Output: nums rotated right by k, modified in place.

Constraints

  • 1 ≤ n ≤ 10^5; O(1) extra space.
  • k may be larger than n — reduce it modulo n first.

Example

  • [1,2,3,4,5,6,7], k=3 → [5,6,7,1,2,3,4].
added …
LeaderboardSalaryAccount