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

Debugging Bottlenecks and Edge Cases

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

Your question is Debugging Bottlenecks and Edge Cases. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

A robotics team building on General Intuition's simulation stack uses this collision-avoidance check inside the robot's control loop, which runs on every tick. In testing, the robot works fine most of the time, but it crashes whenever it comes to a complete stop at a waypoint, and separately crashes in open areas where the obstacle sensor reports nothing nearby.

import math

def time_to_collision(robot_pos, robot_vel, obstacle_pos):
    dx = obstacle_pos[0] - robot_pos[0]
    dy = obstacle_pos[1] - robot_pos[1]
    distance = math.sqrt(dx ** 2 + dy ** 2)
    speed = math.sqrt(robot_vel[0] ** 2 + robot_vel[1] ** 2)
    return distance / speed

def find_nearest_obstacle(robot_pos, obstacles):
    nearest = obstacles[0]
    nearest_dist = math.sqrt((obstacles[0][0] - robot_pos[0]) ** 2 + (obstacles[0][1] - robot_pos[1]) ** 2)
    for obstacle in obstacles:
        dist = math.sqrt((obstacle[0] - robot_pos[0]) ** 2 + (obstacle[1] - robot_pos[1]) ** 2)
        if dist < nearest_dist:
            nearest = obstacle
            nearest_dist = dist
    return nearest

def plan_step(robot_pos, robot_vel, obstacles):
    nearest = find_nearest_obstacle(robot_pos, obstacles)
    ttc = time_to_collision(robot_pos, robot_vel, nearest)
    if ttc < 2.0:
        return "brake"
    return "continue"

Debug this snippet: identify the bottleneck and the edge cases it doesn't handle, and explain how each one shows up at runtime.