TopcoderArchiveVisit Topcoder
SRM1 Nov 2010
SRM 499

SimpleGuess

Problem statement, definition, constraints, and public examples.

Problem Statement

A cat and a rabbit are playing a simple number guessing game. The cat chose two different positive integers X and Y. He then told the rabbit several numbers. One of those numbers was X + Y and another was X - Y. The others were simply made up.

The rabbit thinks the cat prefers large numbers. Given a int[] hints containing the numbers the cat told the rabbit, return the largest possible value of X * Y.

Definition

Class:
SimpleGuess
Method:
getMaximum
Parameters:
int[]
Returns:
int
Method signature:
int getMaximum(int[] hints)
(be sure your method is public)

Constraints

  • hints will contain between 2 and 50 elements, inclusive.
  • Each element of hints will be between 1 and 100, inclusive.
  • All elements of hints will be distinct.
  • There will exist at least one pair of positive integers (X, Y) such that both X + Y and X - Y are elements of hints.

Examples

  1. { 1, 4, 5 }
    Returns: 6
    The rabbit can determine that (X, Y) = (3, 2).
  2. { 1, 4, 5, 8 }
    Returns: 12
    Possible pairs (X, Y) are (3, 2) and (6, 2). The values of X * Y are 6 and 12, respectively, and the largest is 12.
  3. { 9, 8, 7, 6, 5, 4, 3, 2, 1 }
    Returns: 20
  4. { 2, 100 }
    Returns: 2499
  5. { 50, 58, 47, 57, 40 }
    Returns: 441
Back to all problems