Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rotate Array and Special Characters

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

Your question is Rotate Array and Special Characters. 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

DP World systems may need to reorder event identifiers while preserving formatting in human-readable labels. Implement one function that rotates an integer array, computes character frequencies, and reverses only alphanumeric characters while leaving special-character positions unchanged.

Formal Specification

Given an integer array nums, a non-negative rotation amount k, and a string text, return a dictionary with:

  1. rotated: nums rotated to the right by k positions.
  2. frequencies: a case-sensitive frequency dictionary containing every character in text, including spaces and punctuation.
  3. reversed: a string formed by reversing all alphanumeric characters in text, while every non-alphanumeric character remains at its original index. Use Python's str.isalnum() to classify characters.

The input array may be modified in place. The returned array must contain the same values as the input, only in rotated order.

Constraints

  • 0 <= len(nums) <= 10^5
  • 0 <= k <= 10^9
  • 0 <= len(text) <= 10^5
  • Characters are case-sensitive
  • Non-alphanumeric characters remain at their original positions

Function Signature

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