Median of two sorted arrays · Compiler

Median of two sorted arrays

Find the median of the two arrays taken together, counting all duplicates. In the combined sorted order, use the middle value for an odd total length and the arithmetic mean of the two middle values for an even total length.

Input
Line 1 contains the lengths n and m (0 to 100 each). The remaining whitespace-separated integers are the n values of the first array followed by the m values of the second. Each value is from -1000 to 1000. Both arrays are sorted in nondecreasing order and n + m is at least 1.
Output
Print the median with exactly one digit after the decimal point. For integer inputs the result is always exact.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…