Problem Statement
Andrew drew a bunch of points on a sheet of graph paper. You are given the coordinates of these points in two int[]s: X and Y. That is, for each valid i, there is a point at the coordinates (X[i], Y[i]).
Now Andrew wants to draw a rectangle. The sides of the rectangle must be parallel to the coordinate axes. (In other words, each side of the rectangle must be either horizontal or vertical.) Additionally, each of Andrew's points must be inside the rectangle or on its boundary.
Return the area of the smallest possible rectangle Andrew can draw.
Definition
- Class:
- BoundingBox
- Method:
- smallestArea
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int smallestArea(int[] X, int[] Y)
- (be sure your method is public)
Constraints
- X will have between 2 and 50 elements, inclusive.
- X and Y will have the same number of elements.
- Each element of X and Y will be between -100 and 100, inclusive.
- The points described by X and Y will not be in a straight line horizontally or vertically. That is, the smallest rectangle will have a positive area.
Examples
{0,1}{1,0}Returns: 1
{0,-2,-1}{-1,-1,-2}Returns: 2
{0,0,1,0,-1,2}{0,1,2,-2,0,-1}Returns: 12
{9,-88,-40,98,-55,41,-38}{-65,56,-67,7,-58,33,68}Returns: 25110