Problem Statement |
|
A square covers a point on a plane if this point lies on the border of this square.
You will be given int[]s px and py, with the i-th elements of px and py representing x and y coordinates of a point on a plane.
Find the smallest square with its sides parallel to coordinate axes, which can cover all points from the input and return the length of its side.
If no such square exists, return -1.
|
|
Definition |
| Class: | SquareCovering | Method: | getMinimalSide | Parameters: | int[], int[] | Returns: | int | Method signature: | int getMinimalSide(int[] px, int[] py) | (be sure your method is public) |
|
|
|
|
Constraints |
- | px will contain between 2 and 50 elements, inclusive. |
- | px and py will contain the same number of elements. |
- | All elements of px and py will be between -1000 and 1000, inclusive. |
- | All points specified by px and py will be different. |
|
Examples |
0) | |
| | Returns: 1 | Both points can be covered with a square with vertices (0,0), (1,0), (1, 1) and (0, 1). |
|
|
1) | |
| | Returns: -1 | These points can not be covered by a square. |
|
|
2) | |
| |
3) | |
| {-10, 0, 3, -1} | {0, -1, 3, 4} |
| Returns: -1 | These points can be covered by a rectangle, but not by a square. |
|
|
4) | |
| {1,2,3,4,5,6,7,8,9,10} | {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000} |
| Returns: 9 | |
|