Saturday, April 9, 2016

LeetCode Q223: Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane.
Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.
Rectangle Area
Assume that the total area is never beyond the maximum possible value of int.

Solution:
Forget about listing all the possibilities, there is no way you can get everything right during interview by solving this question like that. Instead, we notice that the x and y coordinates of the overlapping part are always ranked as 2nd and 3rd position in both x-axis and y-axis.

No comments:

Post a Comment