Missing number(s) Interview Question Redux

后端 未结 8 788
轮回少年
轮回少年 2021-01-30 07:14

The common interview problem of determining the missing value in a range from 1 to N has been done a thousand times over. Variations include 2 missing values up to K missing val

8条回答
  •  醉话见心
    2021-01-30 07:55

    Because the numbers are taken from a small, finite range, they can be 'sorted' in linear time.

    All we do is initialize an array of 100 booleans, and for each input, set the boolean corresponding to each number in the input, and then step through reporting the unset booleans.

提交回复
热议问题