Count Ways to Place N Delivery Drones With No Shared Flight Lines
Last updated: November 29, 2026
Quick Overview
On an n x n airspace grid, count the ways to place n drones so that no two share a row, a column, or a diagonal, since drones on a shared line could collide.
Amazon
November 29, 20260
0
0 solved
On an n x n airspace grid, count the ways to place n drones so that no two share a row, a column, or a diagonal, since drones on a shared line could collide.
A classic backtracking question dressed in Amazon's drone-delivery framing, used in screens to see whether you can model constraints compactly. The interviewer expects row-by-row placement with O(1) conflict checks via column and diagonal sets, and ideally a bitmask version.
What the Interviewer Expects
- Places one drone per row to remove row conflicts
- Tracks columns, r - c diagonals, and r + c anti-diagonals
- Undoes state on backtrack
- Offers a bitmask version for speed
- Knows the counts for small n (e.g. 8 gives 92)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the actual boards?
- How would you use symmetry to halve the work?
- How would you handle some cells being no-fly zones?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input from 1 to around 12 (output grows fast). Return the number of placements of drones with no two sharing a row, column, diagonal, or anti-diagonal....
High-Level Design
Since each row holds exactly one drone, place them row by row. A cell (r, c) is blocked if column c, diagonal r - c, or anti-diagonal r + c is already used, so three sets give checks. T...