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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
backtracking
bitmasks
constraint satisfaction
N-Queens
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements

Input nn from 1 to around 12 (output grows fast). Return the number of placements of nn 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 O(1)O(1) checks. T...


Submit Your Answer
Markdown supported