Given two non-overlapping axis-aligned rectangles, find the smallest area of an axis-aligned square that covers both.
Easy3GeometryMathInterviewNo attempts yetTime limit2sMemory limit512 MBFarmer John wants to simplify the layout of his farm. Until now his cows grazed in two fenced rectangular pastures. Farmer John would like to replace them with a single square pasture. The new pasture has to cover every region that the two old fences enclosed, and it has to be the smallest square that does so.
The sides of the square pasture are parallel to the x and y axes, and it can be placed anywhere. Find the minimum area of a square that covers all the area the two rectangular pastures used to cover.
The first line contains four space separated integers x1, y1, x2, y2 describing one of the original pastures. All four values are between 0 and 10, inclusive. The lower left corner of that pasture is (x1,y1) and the upper right corner is (x2,y2), with x2>x1 and y2>y1.
The second line describes the second original pasture in the same format as the first line. The two pastures neither overlap nor touch.
Print one line with the minimum area of a square pasture that covers every region the two rectangular pastures originally enclosed.
Consider the case where the first rectangle has corners (6,6) and (8,8) and the second one has corners (1,8) and (4,9). A square fence of side length 7 with corners (1,6) and (8,13) covers both regions. A square of side length 6 cannot cover them, so 7 is the best possible. There are several valid placements for the square of side length 7, since it can be shifted a little up or down.