TopCoder problem "SimpleGuess" used in SRM 499 (Division II Level One)



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

0)
    
{ 1, 4, 5 }
Returns: 6
The rabbit can determine that (X, Y) = (3, 2).
1)
    
{ 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.
2)
    
{ 9, 8, 7, 6, 5, 4, 3, 2, 1 }
Returns: 20
3)
    
{ 2, 100 }
Returns: 2499
4)
    
{ 50, 58, 47, 57, 40 }
Returns: 441

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10763

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14428&pm=10763

Writer:

lyrically

Testers:

PabloGilberto , ivan_metelsky , nika

Problem categories:

Simple Math, Simple Search, Iteration