TopCoder problem "UsingStats" used in TCCC06 Qual 3 (Division I Level One)



Problem Statement

    You have been given a int[] vals that is missing one element. Luckily, you know the mean of the entire set (with the missing element present). Using this information, reconstruct the full data set and return the median.
 

Definition

    
Class:UsingStats
Method:getMedian
Parameters:int[], int
Returns:int
Method signature:int getMedian(int[] vals, int mean)
(be sure your method is public)
    
 

Notes

-The mean of a list of values is their average. The median of a list of values is determined by sorting the list, and then taking the middle element.
 

Constraints

-vals will contain between 2 and 50 elements, inclusive.
-vals will contain an even number of elements.
-Each element of vals will be between -1000 and 1000, inclusive.
-mean will be between -1000 and 1000, inclusive.
 

Examples

0)
    
{50,100}
75
Returns: 75
To have a 75 average, the missing value must be 75. This is also the median of the resulting set.
1)
    
{1,2,3,4}
3
Returns: 3
The missing value is 5. The resulting median is 3.
2)
    
{0,0,100,100}
61
Returns: 100
The missing value is 105, and the resulting median is 100.
3)
    
{889,820,404,-901}
539
Returns: 820
4)
    
{-211,-504,461,283,791,646,205,459,-186,516,-933,762,418,656,746,-368,888,270,-355,-207,-990,435,717,-338}
845
Returns: 418

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10095&pm=6719

Writer:

AdminBrett

Testers:

PabloGilberto , Olexiy , Andrew_Lazarev

Problem categories:

Simple Math