Problem · Array

Rotate Array Right

Learn this problem
MediumOmnissaONSITE INTERVIEW

Problem statement

A quick note: this problem is backed by a real Omnissa onsite interview report that directly named rotating an array right by k steps. The report did not include an exact function interface, examples, constraints, or behavior for large k. The core task match is about 95%.

You are given an integer array nums and an integer k. Rotate the array to the right by k steps and return the rotated array.

Interview Follow-up

This was part of a rapid-fire three-problem round in which the candidate presented brute-force, improved, and optimal approaches and wrote working code for each problem.

Function

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

Examples

Example 1

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

Moving the last three values to the front gives [5,6,7,1,2,3,4].

Example 2

nums = [-1,-100,3,99]k = 2return = [3,99,-1,-100]

After two right rotations, 3 and 99 move to the front.

More Omnissa problems

drafts saved locally
public int[] rotateRight(int[] nums, int k) {
  // write your code here
}
nums[1,2,3,4,5,6,7]
k3
expected[5,6,7,1,2,3,4]
checking account