InterviewDB Question

Nearest Rook - Find the Closest Rook on a Chess Board

Question Details

Problem You have an n x n chessboard with rooks placed at given positions. For each rook, find the nearest other rook by Manhattan distance. If multiple rooks are equidistant, return the one with the smallest row index, then smallest column index. Example: Follow-ups Your brute-force is O(k^2) for k rooks. How do you use a spatial index (k-d tree) to improve this? How does the answer change if distance is Euclidean instead of Manhattan? For a rook that can attack along rows and columns, find the…

Full Details

🔒

Unlock all Two Sigma questions

Full insider details, leaked discussions, and candidate experiences.

Get full access — $100 a year, unlimited access

About This Question

This is a reported interview question from a two sigma interview during the phone round.

It covers the following topics: Coding, Onsite, Phone .