Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

Stretch Problem: Rotate an Array (medium)

This problem is optional. The four problems above cover what the chapter teaches. This one is here for readers who want a harder array question, and nothing later in the course depends on it.

Problem Statement

Given an integer array nums and an integer k, rotate the array to the right by k steps. Every element moves k places to the right, and the elements pushed off the end reappear at the front.

Return the rotated array.

Examples

Example 1

  • Input: nums = [1, 2, 3, 4, 5, 6, 7], k = 3
  • Expected Output: [5, 6, 7, 1, 2, 3, 4]

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content