Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Linked List or Array Challenge

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Linked List or Array Challenge. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Silicon Valley Bank may need to rotate an in-memory sequence of transaction batches before processing a new reporting window. Given an array nums, rotate its elements to the right by k positions and modify the array in place.

Formal Specification

Implement rotate_right(nums, k), where nums is a mutable array of integers and k is a non-negative integer. The function must rearrange nums so that each element moves k positions to the right, wrapping around at the end. Return the modified array. Do not create an array proportional to nums.length.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= k <= 10^9
  • -10^9 <= nums[i] <= 10^9
  • The rotation must use O(1) extra space
  • The input array must be modified in place

Function Signature

def rotate_right(nums, k):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output