Monday, May 16, 2016

Find the bucket | Yaozong's Blog

Find the bucket | Yaozong's BlogGiven an array of numbers, they are arranged so that the a[0] is in the 1st bucket, a[1]a[2] are in the 2nd bucket, a[3]a[4]a[5] is in the 3rd bucket and so on. All the numbers in one bucket are larger than that of the previous bucket. So ALL numbers of bucket 3 will be bigger than ANY number of the bucket 2 and so on. The number given to the function may or may not be in the array. The question is then: given a number, you need to return the bucket index if it is in any bucket. Otherwise, return -1 if this number is not in any of bucket.