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
Implement Algorithm Without Packages
00:00
5 left

Implement Algorithm Without Packages

HardPython

Problem

A workflow tool supporting MSK-IMPACT review represents navigation options as a grid. Find a route from S to T that does not exceed a maximum cumulative risk and minimizes total risk. If multiple routes have the same risk, choose the one with fewer moves. If a tie remains, choose the lexicographically smallest move sequence under D < L < R < U.

You may move one cell at a time in four directions. # cells are blocked. Digit cells have risk values from 1 to 9; entering S or T adds zero risk. Return the move sequence, or "" when no valid route exists. Implement the algorithm without importing packages.

Formal Specification

Implement minimum_risk_route(grid, max_risk), where grid is a non-empty list of equal-length strings containing exactly one S and one T, and max_risk is a non-negative integer. Return a string containing only D, L, R, and U.

Constraints

  • 2 <= len(grid), len(grid[0]) <= 100
  • Every row has the same length
  • The grid contains exactly one S and one T
  • 0 <= max_risk <= 1000
  • At most 9 risk is added by entering one cell

Function Signature

def minimum_risk_route(grid, max_risk):
Interviewer

Your question is Implement Algorithm Without Packages. 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.