An orchard is laid out as m rows of trees with n trees per row. Within each row the tree heights are listed in non-decreasing order (heights across different rows are unrelated to one another). The total number of trees, m * n, is guaranteed to be odd. Determine the median height when all m * n trees are considered together.
Print a single integer: the median height across all m * n trees.
Example 1
Input
3 3 1 3 5 2 6 9 3 5 8
Expected
5
Explanation
Flattening all 9 heights gives 1,3,5,2,6,9,3,5,8, which sorted is 1,2,3,3,5,5,6,8,9. The median (5th of 9) is 5.
Example 2
Input
1 1 7
Expected
7
Explanation
With a single tree, the median is that tree's own height, 7.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →