Statistics

Problem Statement for "MedianOfMedians"

Problem Statement

Recall that the median of a group of numbers is the one in the middle when the numbers are listed in non-decreasing order. Finding the median of a large data set can be expensive, but we can approximate the true median quite cheaply by finding the medians of several small samples and then finding the median of those medians.

Consider a 3-by-3 matrix of digits, where each digit is a sample from some larger data set. Find the median of medians by first calculating the median of each row of the matrix, and then calculating the median of the three medians. For example, if the matrix were

   724
   681
   331 
then the medians of the three rows would be 4, 6, and 3, respectively. The median of these three values is 4.

Create a class MedianOfMedians with a method median that takes a 3-by-3 matrix of digits as a String[] matrix and returns the median of medians. Each String in matrix represents one row and contains exactly three digits.

Definition

Class:
MedianOfMedians
Method:
median
Parameters:
String[]
Returns:
int
Method signature:
int median(String[] matrix)
(be sure your method is public)

Constraints

  • matrix contains exactly three elements.
  • Each element of matrix contains exactly three characters, each of which is a digit ('0'-'9').

Examples

  1. { "724", "681", "331" }

    Returns: 4

    The example above.

  2. { "777", "777", "777" }

    Returns: 7

  3. { "123", "456", "789" }

    Returns: 5

  4. { "987", "321", "654" }

    Returns: 5

  5. { "545", "565", "066" }

    Returns: 5

  6. { "091", "807", "066" }

    Returns: 6

  7. { "314", "159", "265" }

    Returns: 5

  8. { "271", "828", "182" }

    Returns: 2

  9. { "141", "421", "356" }

    Returns: 2

  10. { "134", "217", "728" }

    Returns: 3

  11. { "001", "000", "099" }

    Returns: 0

  12. { "196", "709", "269" }

    Returns: 6

  13. { "000", "099", "999" }

    Returns: 9

  14. { "987", "876", "765" }

    Returns: 7

  15. { "845", "938", "098" }

    Returns: 8

  16. { "734", "129", "091" }

    Returns: 2

  17. { "901", "823", "567" }

    Returns: 3

  18. { "444", "000", "888" }

    Returns: 4

  19. { "358", "979", "323" }

    Returns: 5

  20. { "846", "264", "338" }

    Returns: 4

  21. { "070", "106", "781" }

    Returns: 1

  22. { "097", "720", "008" }

    Returns: 2

  23. { "100", "010", "100" }

    Returns: 0

  24. { "129", "222", "222" }

    Returns: 2

  25. { "555", "555", "999" }

    Returns: 5

  26. { "461", "123", "456" }

    Returns: 4

  27. { "542", "654", "321" }

    Returns: 4

  28. { "556", "556", "556" }

    Returns: 5

  29. { "754", "788", "169" }

    Returns: 6


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: