Every Word Square
All words have the same length n. A word square is n of these words written one under another so that, for every k, row k and column k read the same. A word may appear more than once in a square.
Return every word square, each as its rows from top to bottom joined by single spaces, in any order.
Example 1
words ["bit","ice","ten","pit","eat"]
returns ["bit ice ten","pit ice ten"]
Under bit or pit fit ice and ten: the columns then read the same words as the rows. No square starts with any other word.
Example 2
words ["ab","ba"]
returns ["ab ba","ba ab"]
With two rows, the second letter of the first row must be the first letter of the second row.
Example 3
words ["dog","cat"]
returns []
A second row would have to start with o or with a.
Constraints
1 <= len(words) <= 24, all different- every word has the same length, 1 to 5 lowercase letters
- there are at most 150 word squares
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.