Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Implement Algorithm Without Packages

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

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

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output