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
Step_K Time-Driven Ball Flip
00:00
5 left

Step_K Time-Driven Ball Flip

MediumPython

Problem

Given n balls with initial positions, all white; after each step, balls on marked positions flip (white to black or black to white) and every position advances by 1 (e.g. N=5, marked positions [1,3]). Write a step_k function with O(n) time complexity.

The technical phone screen uses five cyclic positions, numbered 0 through 4. At each step, determine which balls currently occupy a marked position, flip those balls, then advance every ball by one position modulo 5.

Contract

Implement step_k(initial_positions, marked_positions, k). Return a list aligned with initial_positions, where each item is [final_position, final_color]. Every ball starts white, and k may be zero or very large.

Constraints

  • 1 <= len(initial_positions) <= 100
  • 0 <= initial_positions[i] <= 4
  • 0 <= marked_positions[i] <= 4
  • marked_positions contains distinct positions
  • 0 <= k <= 10^18

Function Signature

def step_k(initial_positions, marked_positions, k):
Interviewer

Your question is Step_K Time-Driven Ball Flip. 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.