TopcoderArchive
SRM9 Aug 2019
SRM 764

RectangleHunt

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a set of points, given as (x, y) coordinates in int[]s x and y.

Return the area of the largest rectangle that can be formed from four of the points. If no four points can form a rectangle, return -1.

Definition

Class:
RectangleHunt
Method:
largest
Parameters:
int[], int[]
Returns:
double
Method signature:
double largest(int[] x, int[] y)
(be sure your method is public)

Notes

  • Your return value must be within 1e-9 absolute or relative error to be considered correct.

Constraints

  • x will contain between 4 and 50 elements, inclsuive.
  • x and y will contain the same number of elements.
  • Each element of x will be between 0 and 1000, inclusive.
  • Each element of y will be between 0 and 1000, inclusive.
  • No two points specified by x and y will be the same.

Examples

  1. {0, 1, 0, 1}
    {0, 2, 2, 0}
    Returns: 2.0
    There is only a single rectangle, 2x1 in size.
  2. {0, 1, 0, 1}
    {0, 2, 2, 3}
    Returns: -1.0
    These four points don't form a rectangle.
  3. {0, 5, 6, 11}
    {5, 2, 15, 12}
    Returns: 68.0
    The rectangle isn't necessarily aligned along the x-y grid.
Back to all problems