Given n numbers and a black-box comparison function cmp(a,b) that returns the wrong answer 10% of the time (deterministically, for the same arguments), find the top k elements; discuss the approach verbally.
Asked in the Onsite coding (45 min) stage. Verbal only, no code required per OP reply; exact top-k cannot be guaranteed.
For executable evaluation, cmp is represented as an n x n matrix, where cmp[i][j] is the comparison result for nums[i] and nums[j]: positive means nums[i] ranks higher, negative means lower, and zero means equal. Return the selected elements in descending estimated rank order.
def top_k_noisy(nums, k, cmp):