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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Shortest Path Avoiding Compromise
00:00
5 left

Shortest Path Avoiding Compromise

HardPython

Problem

Given a network topology represented as a graph, find the shortest path between two nodes that avoids a set of compromised servers at Intuit.

Treat the graph as directed and weighted, with nonnegative edge latencies. Return the node sequence for the minimum-latency safe path, or [] if no such path exists. The path must also be empty when start or end is compromised.

Input: graph is a dictionary mapping each node to [neighbor, latency] pairs; start, end, and compromised are strings and a list of strings. Output: return a list of node names.

Example: graph = {"gateway": [["backup", 5]], "backup": [["payroll", 1]], "payroll": []}, start = "gateway", end = "payroll", compromised = [] returns ["gateway", "backup", "payroll"].

Constraints: Up to 10^4 nodes and 10^5 directed edges; latencies are nonnegative integers.

Constraints

  • The graph contains at most 10^4 nodes and 10^5 directed edges
  • Each adjacency entry is a pair of a node name and a nonnegative integer latency
  • Node names are unique strings
  • The graph may omit nodes with no outgoing edges
  • The returned path must contain no compromised node

Function Signature

def shortest_safe_path(graph, start, end, compromised):
Interviewer

Your question is Shortest Path Avoiding Compromise. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.