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
Graph-Based Neighbor Discovery
00:00
5 left

Graph-Based Neighbor Discovery

HardPython

Problem

Tell me how you would find and rank nearby hosts for Neighbor using graph-based neighbor discovery and related algorithms.

Implement rank_nearby_hosts(graph, start, host_scores, k). graph maps each node ID to adjacent node IDs, and host_scores maps host IDs to numeric scores. Return up to k reachable hosts, excluding start, ordered by shortest graph distance, highest score, then lexicographically smallest host ID.

Constraints

  • 1 <= number of graph nodes <= 1000
  • 0 <= number of graph edges <= 5000
  • 0 <= len(host_scores) <= 1000
  • Host IDs are unique strings
  • All host scores are integers
  • The graph is unweighted and may be disconnected
  • Return at most k hosts

Function Signature

def rank_nearby_hosts(graph, start, host_scores, k):
Interviewer

Your question is Graph-Based Neighbor Discovery. 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.