Company: Idfc_29march
Difficulty: medium
Top K Bit Distances Problem Description The bit distance, d of an integer, x is defined as the maximum distance between any two consecutive set bits. For example, let x = 1036 , which, represented in binary, is 10000001100 . The distances between consecutive set bits are [0, 6] , respectively. Hence, the bit distance d(x) is equal to 6 . If there is only one set bit, the bit distance is considered to be -1 . Given an integer array, the goal is to find the top k integers with maximum bit distances. For the given array of integers, sort the integers in decreasing order of their bit distances. If there are multiple integers with the same bit distances, sort them in decreasing order by their value. Report the first k integers of the array thus obtained. For example, let n = 5, numbers = [12, 4, 5, 10, 8], and k = 3 . The binary representation of array numbers is [1100, 100, 101, 1010, 1000] . The corresponding bit distances d are [0, -1, 1, 1, -1] . 5 and 10 are the integers with the highe