Loading
Loading
A city block is laid out as an n × n grid of rooftops. Engineers must mount exactly n laser beacons, one per rooftop at most, so that no two beacons can see each other. A beacon sees along its row, its column and both diagonals, any distance away.
Return how many different layouts satisfy the rule.
n = 4row 0 → col 0row 1 can use col 2 or 3; both dead-end laterrow 0 → col 1forces col 3, then col 0, then col 2: a layoutrow 0 → col 2the mirror image: cols 2, 0, 3, 1row 0 → col 3dead-ends, like col 02Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Two layouts work: columns 1,3,0,2 and 2,0,3,1 by row.
Example 2
A single rooftop holds the single beacon.
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n!) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.