Back to problems

Find Median (Oracle Variant)

Algorithm · Apple · Medium

You need to determine the median of a hidden integer array nums, which may contain either unique values or duplicates. Direct inspection of the array is unavailable; instead, you can use these three oracle queries: int countLess(int x) — reports how many entries of nums are smaller than x. int countGreater(int x) — reports how many entries of nums exceed x. int total() — gives the array length n. Each query may use any integer x, whether or not that value occurs in nums.…

Checking your access…