Imagine you have a collection of words arranged in a grid, like a crossword puzzle. Your task is to determine if this grid forms a valid word square - a special arrangement where each row reads exactly the same as its corresponding column.
Given an array of strings words, return true if it forms a valid word square. A sequence of strings forms a valid word square if the k-th row and k-th column read the same string, where 0 ≤ k < max(numRows, numColumns).
Example: If words = ["abcd", "bnrt", "crmy", "dtye"], then:
• Row 0: "abcd" vs Column 0: "abcd" ✓
• Row 1: "bnrt" vs Column 1: "bnrt" ✓
• Row 2: "crmy" vs Column 2: "crmy" ✓
• Row 3: "dtye" vs Column 3: "dtye" ✓
This is a valid word square because each row matches its corresponding column perfectly!
Input & Output
Constraints
- 1 ≤ words.length ≤ 500
- 1 ≤ words[i].length ≤ 500
- words[i] consists of only lowercase English letters
- Matrix dimensions may be uneven - number of rows may differ from maximum column length