Missing number(s) Interview Question Redux

后端 未结 8 812
轮回少年
轮回少年 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:41

    Whether the given solution is theoretically better than the sorting one depends on N and K. While your solution has complexity of O(N*log(N)), the given solution is O(N*K). I think that the given solution is (same as the sorting solution) able to solve any range [A, B] just by transforming the range [A, B] to [1, N].

提交回复
热议问题