FastPrepRotate an Array Right by K Steps
Problems/Rotate an Array Right by K Steps

Rotate an Array Right by K Steps

Qualys logoQualys● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Qualys onsite interview. The report asks for a right rotation, a comparison of approaches, and a detailed explanation of the three-reversal method, including k modulo n. We chose that the function returns the changed array.

Given an integer array nums and a nonnegative integer k, rotate the array to the right by k positions.

Perform the rotation in place. For the practice runner, return the same array after it has been mutated.

Function

rotate(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 move to the front while their relative order is preserved.

Example 2

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

After two right rotations, 3 and 99 precede the original first two values.

Constraints

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

More Qualys Onsite Interview questions

  • Delete a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
  • Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Oct 2026
  • Implement Binary SearchONSITE INTERVIEW · Seen Oct 2026
  • Insert a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Valid Triangle NumberBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Run-Length Encoded Vector Dot ProductMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
All Qualys interview questionsSee Qualys hiring insights
Saved
class Solution {
    public int[] rotate(int[] nums, int k) {
      // Write your code here.
    }

}
Checking account…