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 Provided Code

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

Your question is Debugging Provided Code. 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

Via Transportation shows dispatchers a live queue of ride requests for a service zone, polling the backend every few seconds and letting a dispatcher click a request to flag the one with the shortest ETA. Here is the component as it currently exists.

import { useEffect, useState } from "react";

interface RideRequest {
  id: string;
  riderName: string;
  etaMinutes: number;
}

function LiveRideQueue({ zoneId }: { zoneId: string }) {
  const [requests, setRequests] = useState<RideRequest[]>([]);
  const [selectedId, setSelectedId] = useState("");

  useEffect(() => {
    const interval = setInterval(() => {
      fetchRequestsForZone(zoneId).then((data) => {
        requests.push(...data);
        setRequests(requests);
      });
    }, 5000);
  }, []);

  function selectFastest() {
    const sorted = requests.sort((a, b) => a.etaMinutes - b.etaMinutes);
    setSelectedId(sorted[0].id);
  }

  return (
    <ul>
      {requests.map((req, index) => (
        <li key={index} onClick={selectFastest}>
          {req.riderName} - {req.etaMinutes} min {req.id === selectedId && "(selected)"}
        </li>
      ))}
    </ul>
  );
}

What is the issue in this component? Walk through everything wrong with it and explain what you would change and why.