#K44832. Find the Median
Find the Median
Find the Median
Problem Description:
You are given an array of distinct integers. Your task is to sort the array and then find its median. The median is defined as follows:
( \text{Median} = \begin{cases} a_{\frac{n+1}{2}} & \text{if } n \text{ is odd},\ \frac{a_{\frac{n}{2}} + a_{\frac{n}{2}+1}}{2} & \text{if } n \text{ is even} \end{cases} )
Note that when implementing the solution (using 0-indexed arrays), for an even number of elements the two middle numbers are at positions (n/2 - 1) and (n/2), and their average should be rounded to one decimal place. You need to process multiple test cases.
inputFormat
The input consists of multiple test cases. The first line contains an integer (T) representing the number of test cases. Each test case is described in two lines:
1. The first line contains an integer (N) denoting the number of elements in the array.
2. The second line contains (N) space-separated distinct integers.
outputFormat
For each test case, output the median on a separate line. If the median is computed from an odd number of elements, output it as an integer. If it is computed from an even number of elements, output it as a decimal rounded to one decimal place.## sample
4
5
10 5 1 3 9
6
11 2 4 8 1 6
1
42
2
1 3
5
5.0
42
2.0
</p>