The "Valid Word Square" interview question asks you to verify if a given sequence of strings forms a valid word square. A word square is a square matrix where the k-th row and the k-th column are identical. For example, if the first row is "BALL", the first column must also be "B", "A", "L", "L".
Google and Apple use the "Valid Word Square" coding problem to test a candidate's familiarity with 2D array structures and matrix symmetry. It challenges you to handle "jagged" arrays (where rows might have different lengths) while maintaining clear and concise logic.
The core pattern is the "Matrix interview pattern." You iterate through each character in the matrix using nested loops. For each character at position (r, c), you must check if it is equal to the character at (c, r). The trick is handling cases where the column or row index might be out of bounds due to unequal string lengths.
Words: ["ABC", "BNP", "CPQ"]
A common mistake is assuming all strings in the list have the same length. If the first word is length 4, but there are only 3 words total, it cannot be a valid square. Another error is failing to check bounds before accessing words[c][r], which will cause a crash if a row is shorter than the column index we are checking against.
When solving the "Valid Word Square" coding problem, treat it as a symmetry check. Before you compare words[r][c] and words[c][r], always verify that c < words.length and r < words[c].length. This defensive programming prevents runtime errors and shows the interviewer you consider all edge cases.