FunctionRacerProblemsRace

Every Word Square

HardRecursionPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems