FastPrepRotate Array by K
Problems/Rotate Array by K

Rotate Array by K

Apple logoApple● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple new grad phone screen. The report names rotating an array by k. Our version is about 65% the same as that short recollection. We chose to rotate to the right, what happens for empty input, and the input limits.

You are given an integer array nums and a nonnegative integer k. Rotate the array k positions to the right and return the result. Each step moves every value one place right, and the last value wraps around to the front. If the array is empty, return an empty array.

Every value must stay in the result, and the values keep their order around the circle. You may build a new array. You do not have to change nums in place.

Function

rotateArray(nums: int[], k: int) → int[]

Examples

Example 1

nums = [1,2,3,4,5]k = 2return = [4,5,1,2,3]

Each step moves the last value to the front. After two steps, the last two values sit at the front, followed by the rest in their old order.

Example 2

nums = [-1,7,0]k = 4return = [0,-1,7]

The array has three values, so every three steps bring it back to where it started. Four steps are the same as one step, which moves the last value to the front.

Constraints

  • 0 <= nums.length <= 10^5.
  • -10^9 <= nums[i] <= 10^9.
  • 0 <= k <= 10^9.

More Apple Phone Screen questions

  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
  • Evaluate DivisionPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
  • Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
  • Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
  • Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Numerically Stable SoftmaxWaymo · PHONE SCREENWaymo interview questions
  • Streaming Entropy, Part 1: Batch EntropyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Length of a Document Reached Through a Random TokenMercor · PHONE SCREENMercor interview questions
  • Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
  • Exponential Backoff DelaysWonderful · PHONE SCREEN
  • Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
  • Average Grades per StudentHartford Financial Services · PHONE SCREENHartford Financial Services interview questions

Interview reports that mention this question

  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
  • Apple New Grad SWE Interviews: 37 Experiences (Part 1 of 3)

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int[] rotateArray(int[] nums, int k) {
        // Write your solution here.
    }

}
Checking account…