Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Frequency Counter or Array Rotation

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

Your question is Frequency Counter or Array Rotation. 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

A Finastra Fusion processing component receives payment records in chronological order. Given an array of records and a non-negative integer k, rotate the array to the right by k positions in place, then return the modified array.

Formal Specification

Implement rotate_array(nums, k) where nums is a mutable list of integers and k is an integer. The function must modify nums directly and return the same list object. If k is larger than the array length, reduce it using modulo arithmetic.

Use only O(1) additional space apart from a constant number of variables.

Constraints

  • 0 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • 0 <= k <= 10^9
  • The rotation must be performed in place

Function Signature

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