AI Interview Prep is optimized for larger screens
Please open this on a laptop or desktop (1024px and wider) to use the full editor, whiteboard, and AI coaching surface.
Find the City With the Smallest Number of Neighbors at a Threshold Distance
MediumUnderstand the problem
Restate the problem precisely. Interviewers reward candidates who pause, define the contract, and name the guarantees before coding.
There are `n` cities numbered from 0 to n-1. Given the array `edges` where `edges[i] = [from, to, weight]` represents a bidirectional weighted edge, and an integer `distanceThreshold`, return the city with the *smallest* number of cities that are reachable through some path with total distance at most `distanceThreshold`. If there is more than one such city, return the city with the *greatest* number.
Once you've drafted a response, click Submit for AI review and a senior engineer will critique your reasoning.