Product
Pricing
Blog
Forum
NEW
Referral
Description
Solution
Discussion
Submissions
Ask AI
AI Insights
Quick Summary
Given a set of cities with coordinates, efficiently answer queries for the nearest city sharing the same x or y coordinate.
Distance is calculated using Manhattan distance, with lexicographical order as the tie-breaker for city names.
Requires preprocessing coordinates into structured collections to support fast, repeated lookups.
What This Tests
Hash map organization and data preprocessing
Binary search on sorted arrays or lists
Geometric distance calculation and comparison logic
Handling multi-criteria tie-breaking conditions
Common Patterns
Binary Search
Hashing
Sorting
Collapse
Hint 1
Hint 2
Hint 3
What Interviewers May Ask Next
Report
Report seen similar question in interview
Accepted
805
/2k
Acceptance Rate
40.2%
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
Python3
Auto
Debug
Run
Submit
Test Cases
Input
Output
Expected