Skip to main content
All Questions

Find where to place the Nth rook using a rook-counting function.

Unlock detailed company stats for this questionUpgrade

On an NxN board, N-1 rooks already stand so that no two attack each other (no row and no column contains more than one rook). Place the Nth rook and return its position (i, j), but you do not know where the current rooks are. You have countRooksInsideRectangle(a, b, c, d), which returns the number of rooks within the rectangle formed by horizontals a, b (a <= b) and verticals c, d (c <= d). Example: n=3, countRooksInsideRectangle(2,3,1,3) -> 2, countRooksInsideRectangle(1,1,1,1) -> 0, answer: (1,1) (the board is 1-indexed).

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.