Given numbers from 1 to 2^32-1, one is missing. How to find the missing number optimally?

前端 未结 5 1055
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 03:58

You are given 2^32-2 unique numbers that range from 1 to 2^32-1. It\'s impossible to fit all the numbers into memory (thus sorting is not an option). You are asked to find t

5条回答
  •  一生所求
    2020-12-14 05:03

    Assuming you can get the Size() you can use some binary approach. Select the set of numbers n where n< 2^32 -2 / 2. then get a count. The missing side should report a lower count. Do the process iteratively then you will get the answer

提交回复
热议问题