Median of Two Sorted Arrays
a and b are sorted from smallest to largest. Return the median of all their numbers together: the middle number when there is an odd count, or the average of the two middle numbers when there is an even count.
Answers within 0.000001 of the exact value are accepted.
Constraints
- 0 ≤ length of
a, length ofb≤ 1,000, and together at least 1 - -1,000,000 ≤ each number ≤ 1,000,000
Example 1
Input
a = [1,3]
b = [2]
Output
2
Why:
All together: 1, 2, 3. The middle is 2.
Example 2
Input
a = [1,2]
b = [3,4]
Output
2.5
Why:
1, 2, 3, 4: the average of 2 and 3.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –