Missing number(s) Interview Question Redux

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

    I already answered it HERE

    You can also create an array of boolean of the size last_element_in_the_existing_array + 1.

    In a for loop mark all the element true that are present in the existing array.

    In another for loop print the index of the elements which contains false AKA The missing ones.

    Time Complexity: O(last_element_in_the_existing_array)

    Space Complexity: O(array.length)

提交回复
热议问题