The TransCompilator

Solved LeetCode program · 51 of 1,000

#0051 · N-Queens

Hard Array chunk-02.md

Original English source

Keep a shared queens as an empty list of whole numbers. Keep a shared parts as an empty list of text. Keep a shared answers as an empty list of text. Keep a shared built as empty text. Keep a shared piece as empty text. Keep a shared safe of 0.
To check square at column (a whole number) for row (a whole number). Set safe to 1.
For every prior from 0 to row minus 1.
The other is item prior of queens. If other is column, set safe to 0. The difference is column minus other. If difference is less than 0, set difference to 0 minus difference. The distance is row minus prior. If difference is distance, set safe to 0.

To place from level (a whole number). If level is 4, The built is join parts with ",", Place built into answers, then return.
For every candidate from 0 to 3.
Check square at candidate for level. If safe is 1, Place candidate into queens, Set piece to format whole number candidate as text, Place piece into parts, place from level plus 1, remove the last item from queens, remove the last item from parts.

Place from 0. For each answer in answers, show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

1,3,0,2
2,0,3,1