Statistics

Problem Statement for "Median"

Problem Statement

PROBLEM STATEMENT

Create a class Median that contains the method findMedian, which takes an int[]
values as input and returns an integer representing the median of the integers
in values.  If the decimal portion of the median is .5, round up to the nearest
integer.  (3.5 is rounded to 4 and -3.5 is rounded to -3)

The median of a set of numbers is the middle number when the numbers are sorted
in ascending (or descending) order.  If there is an even amount of numbers in
the set, then the median is the arithmetic mean (or average) of the two middle
numbers.


DEFINITION
Class: Median
Method: findMedian
Parameters: int[]
Returns: int
Method signature (be sure your method is public):  int findMedian(int[] values);


TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
- values will contain between 1 and 50 elements, inclusive
- Each integer in values will be between -1000 and 1000, inclusive.


EXAMPLES
1) values = {1, 2, 3, 4, 5}

returns: 3


2) values = {1, 4, 15, 9}

The median is (4+9)/2 = 6.5.  returns: 7


3) values = {14, -8, 16, 12, 13}

returns: 13

4) values = {-1000, -1000}

returns: -1000

Definition

Class:
Median
Method:
findMedian
Parameters:
int[]
Returns:
int
Method signature:
int findMedian(int[] param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: