4 ms·
An amazing read, and almost perfect! There's a bug in the Solve "function" due to which you'll get the right answer only for 1x1, 5x5 and 7x7 (I checked till 8
by jtinder 4y ago
An amazing read, and almost perfect!
There's a bug in the Solve "function" due to which you'll get the right answer only for 1x1, 5x5 and 7x7 (I checked till 8x8).
The base case makes a wrong assumption that there will always be a candidate available for the last row. If there are no candidates available, it should return Nil, and backtrack.
Basically, replace
Concat<candidates, placedQueens>
with
candidates extends Cons<infer x, any>
? Cons<x, placedQueens>
: Nil
- ycitm 4y agoAh, thank you so much! Great spot. I've corrected this, and credited you in the errata - https://www.richard-towers.com/2023/03/11/typescripting-the-technical-interview.html#errata https://www.richard-towers.com/2023/03/11/typescripting-the-...