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
Shortest Time to Treasure in a Time-Scheduled Maze
00:00
5 left

Shortest Time to Treasure in a Time-Scheduled Maze

HardPython

Problem

A maze where every room has four doors, each opening clockwise on a schedule keyed to time mod 4; starting from a given initial door/treasure configuration at time 0, find the minimum time to collect all k treasures in the maze and then reach the end room.

Asked in the Onsite coding stage. Candidate attempted BFS and DP approaches but could not complete a working solution in the interview.

Implement minimum_time(doors, start, end, k, treasure_masks, initial_doors). doors[r][d] is the destination through room r's door d, or -1; at time t, door (initial_doors[r] + t) % 4 is open. A move or a wait takes one unit of time. treasure_masks[r] identifies treasures in room r. Return the minimum time, or -1 if impossible.

Constraints

  • 1 <= len(doors) <= 100
  • Each room has exactly four door entries
  • 0 <= start, end < len(doors)
  • 0 <= k <= 15
  • Each destination is -1 or a valid room index
  • Each treasure mask uses only the lowest k bits
  • 0 <= initial_doors[r] < 4
  • A room may contain multiple treasures

Function Signature

def minimum_time(doors, start, end, k, treasure_masks, initial_doors):
Interviewer

Your question is Shortest Time to Treasure in a Time-Scheduled Maze. 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.