← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
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:
int countLess(int x) — returns the number of elements in nums strictly less than x.int countGreater(int x) — returns the number of elements in nums strictly greater than x.int total() — returns n, the total number of elements.
You may call x with any integer value; it does not have to be an element of nums.
Task. Return the median of nums, defined as the k-th smallest element where k = (n + 1) / 2 (using integer division). For odd n this is the middle element; for even n this is the lower of the two central elements. The median is guaranteed to be a value present in nums.
Design goal. Your solution should use O(log M) oracle calls, where M is the value range of nums — significantly better than reading every element.
For the auto-grader, the function signature is simplified to accept nums directly, but treat access as oracle-only: your solution should not rely on reading nums by index or sorting it. Use the oracle helpers defined inside your function.Sorted: [1, 5, 5, 5, 9]. k = 3 → the 3rd smallest is 5. Note: binary search still works with duplicates.