Nearest Neighbouring City

Problem Overview

  • For each queried city, return the nearest city sharing its x or y coordinate by Manhattan distance; if none, return "NONE".
  • Input: city list [name, x, y] and query names; up to 1e5 cities and 1e5 queries; coordinates up to 1e9; names and coordinates are unique.
  • Output: the nearest city name per query.
  • Context: cities placed on a Cartesian grid with integer coordinates.
  • From Akuna interviews; a common coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: