Best Solution | C++
IntuitionTo solve this problem, we need to determine the largest possible square side length (maxLen) that can be cut from any of the given rectangles and then
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To solve this problem, we need to determine the largest possible square side length (maxLen) that can be cut from any of the given rectangles and then count how many rectangles can form a square of that size.

# Approach
<!-- Describe your approach to solving the problem. -->
Find the Maximum Possible Square Side (maxLen)

The largest square that can be cut from a rectangle [li, wi] is min(li, wi).
Iterate through all rectangles and track the maximum min(li, wi), which gives maxLen.
Count Rectangles That Can Form maxLen

Iterate through the rectangles again and count how many of them have min(li, wi) == maxLen.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)

# Code
```cpp []
#include <vector>
#include <algorithm>

class Solution {
public:
    int countGoodRectangles(std::vector<std::vector<int>>& rectangles) {
        int maxLen = 0, count = 0;

        for (const auto& rect : rectangles) {
            int side = std::min(rect[0], rect[1]);  // Maximum square side that can be cut
            if (side > maxLen) {
                maxLen = side;
                count = 1;  // Reset count since we found a new max
            } else if (side == maxLen) {
                count++;  // Increment count if another rectangle can form the largest square
            }
        }

        return count;
    }
};

```
['C++']