Skip to main content
LeetCode 422, Easy. Topics: Array, Matrix. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

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 column read the same string, where 0 <= k < max(numRows, numColumns).

Examples

Example 1
Example 2
Example 3

Constraints

  • 1 <= words.length <= 500
  • 1 <= words[i].length <= 500
  • words[i] consists of only lower-case English letters.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026