← 返回 apple 的题目列表Find Median (Oracle Variant)
类型:qbank
You are asked to find the median of an unseen array nums of n distinct or repeating integers. You cannot read the array directly — instead, you are given three oracle operations:.
Examples
Example 1:
Input: nums = [3, 1, 5]
Output: 3
Explanation:
Sorted: [1, 3, 5]. k = (3 + 1) / 2 = 2 → the 2nd smallest is 3.
Example 2:
Input: nums = [7, 2, 9, 4, 6]
Output: 6
Explanation:
Sorted: [2, 4, 6, 7, 9]. k = 3 → the 3rd smallest is 6.
Example 3:
Input: nums = [5, 5, 5, 1, 9]
Output: 5
Explanation:
Sorted: [1, 5, 5, 5, 9]. k = 3 → the 3rd smallest is 5. Note: binary search still works with duplicates.
Constraints
1 <= n <= 10^5
-10^9 <= nums[i] <= 10^9
The median is guaranteed to be an element of nums.