πŸ“ Problem Details

πŸ’­What Were My Initial Thoughts?

- take the minimum element between the length and width for each rectangle, which will form a square
- record the max of the above elements as we iterate thorugh the array
- have a counter for every instance of the maxElement

πŸ€”What Did I Struggle With?

got this quickly in the interview

πŸ’‘ Explanation of Solution

same as intuition

βŒ› Complexity Analysis

Time Complexity: O(n)

Space Complexity: O(1)

πŸ’» Implementation of Solution

class Solution {
public:
    int countGoodRectangles(vector<vector<int>>& rectangles) {
        int maxSquare = INT_MIN;
        int counter = 0; 
        for(auto rectangle : rectangles) {
            int possibleSquare = min(rectangle[0], rectangle[1]);
 
            if(possibleSquare > maxSquare) {
                maxSquare = possibleSquare;
                counter = 1;
            }
            else if(possibleSquare == maxSquare)
                counter++;
        }
 
        return counter;
    }
};