Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Rotate a String With Constraints
00:00
5 left

Rotate a String With Constraints

MediumPython

Problem

Datavant processing utilities often validate equivalent identifiers and reorder event data before downstream handling. Implement a rotation check using a dedicated string-rotation helper, then implement an array item move operation.

Write these functions:

  1. rotate_string(value, shift): return value left-rotated by shift positions. Normalize shifts larger than the string length.
  2. is_rotation(first, second): return True if second can be produced by rotating first any number of positions. This function must call rotate_string; do not solve the check with only a concatenation expression or a single inline function.
  3. move_index(values, from_index, to_index): remove the item currently at from_index and insert it at to_index in the resulting array. Return the modified array. The input array may be copied or modified in place, but the returned ordering must be correct.

The required interview entry point is validate_and_move, which returns a dictionary containing the rotation result and moved array.

Formal Specification

first and second are strings. values is a list of integers, and both indices are valid. Return {"is_rotation": bool, "array": list[int]}.

Constraints

  • 0 <= len(first), len(second) <= 2,000
  • 0 <= len(values) <= 1,000
  • Indices are valid whenever values is non-empty
  • to_index is the final index after the source item is removed
  • Strings contain arbitrary characters and are case-sensitive

Function Signature

def validate_and_move(first, second, values, from_index, to_index):
Interviewer

Your question is Rotate a String With Constraints. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.