FastPrepRotate an Array In Place
Problems/Rotate an Array In Place

Rotate an Array In Place

Adobe logoAdobe● MediumFULLTIMEOAPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked for array rotation and an O(n)-time, O(1)-space solution. The report gives no numeric bounds; the bounds shown here define this version.

The judged core task matches the report at about 98%.

Rotate nums to the right by k positions. Modify the given array and return it. A right rotation moves the last element to the front.

Use O(n) time and O(1) extra space, where n is the array length.

Function

rotateArray(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]

The last three values, [5,6,7], move before [1,2,3,4].

Example 2

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

The last two values move to the front, preserving the order inside each part.

Constraints

  • For this exercise, assume 1 <= nums.length <= 100000.
  • For this exercise, assume -10^9 <= nums[i] <= 10^9.
  • For this exercise, assume 0 <= k <= 10^9.

Source note: Original OA task images and any included source example. The practice contract follows the rules stated in the problem and source note.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Top-Funded Villages and ProjectsOA · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[] rotateArray(int[] nums, int k) {
    // Write your solution here.
}
Checking account…