LeetCode solutions

1843. Number Of Rectangles That Can Form The Largest Square

My accepted Python solution to LeetCode problem 1843, Number Of Rectangles That Can Form The Largest Square, running in 160ms.

  • Difficulty: Easy
  • Python
  • Runtime 160ms
  • Memory 18MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 160ms, memory 18MB, accepted 2025-12-31.

python
class Solution:
    def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
        max_squares = [min(l, w) for l, w in rectangles]
        max_len = max(max_squares)
        return sum(1 for sq in max_squares if sq == max_len)

Source