|
| 1 | +<p>Given an array of <strong>unique</strong> strings <code>words</code>, return <em>all the </em><strong><a href="https://en.wikipedia.org/wiki/Word_square" target="_blank">word squares</a></strong><em> you can build from </em><code>words</code>. The same word from <code>words</code> can be used <strong>multiple times</strong>. You can return the answer in <strong>any order</strong>.</p> |
| 2 | + |
| 3 | +<p>A sequence of strings forms a valid <strong>word square</strong> if the <code>k<sup>th</sup></code> row and column read the same string, where <code>0 <= k < max(numRows, numColumns)</code>.</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>For example, the word sequence <code>["ball","area","lead","lady"]</code> forms a word square because each word reads the same both horizontally and vertically.</li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> words = ["area","lead","wall","lady","ball"] |
| 14 | +<strong>Output:</strong> [["ball","area","lead","lady"],["wall","area","lead","lady"]] |
| 15 | +<strong>Explanation:</strong> |
| 16 | +The output consists of two word squares. The order of output does not matter (just the order of words in each word square matters). |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong class="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>Input:</strong> words = ["abat","baba","atan","atal"] |
| 23 | +<strong>Output:</strong> [["baba","abat","baba","atal"],["baba","abat","baba","atan"]] |
| 24 | +<strong>Explanation:</strong> |
| 25 | +The output consists of two word squares. The order of output does not matter (just the order of words in each word square matters). |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p> </p> |
| 29 | +<p><strong>Constraints:</strong></p> |
| 30 | + |
| 31 | +<ul> |
| 32 | + <li><code>1 <= words.length <= 1000</code></li> |
| 33 | + <li><code>1 <= words[i].length <= 4</code></li> |
| 34 | + <li>All <code>words[i]</code> have the same length.</li> |
| 35 | + <li><code>words[i]</code> consists of only lowercase English letters.</li> |
| 36 | + <li>All <code>words[i]</code> are <strong>unique</strong>.</li> |
| 37 | +</ul> |
0 commit comments