Java - EXPLANATION - OVERLAP AREA - E A S Y


  • 0
    J

    Imagine drawing squares on top of a grid paper. These squares are the "ops" parameter.

    Since the squares always start on the top right-hand corner, we gain valuable information from this.

    1. There is a guarantee to be an overlap.
    2. What ever that overlap is, the final answer is just the area of the overlap section.
    class Solution {
        public int maxCount(int m, int n, int[][] ops) {
            int height = m, width = n;
            
            for(int i = 0; i < ops.length; i++) {
                if(ops[i][0] < height) height = ops[i][0];
                if(ops[i][1] < width) width = ops[i][1];
            }
            
            return height * width;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.