Missing Numbers

  • + 50 comments

    A simple solution i would think of is,

    STEP-1: Create a array initially with size 10001 with all zeros.

    STEP-2: We are going to decrement the value corresponding to the value that we read as input. for example if the first element of list A is 200, then array[200]--.. Similarly we decrement the values for list A.

    STEP-3: Similarly when reading list B increment the values. Since the elements of list A are lost, the resulting values in the array after this operation will be positive.

    STEP-4: Print all the index of array with value grater than 0. The numbers will be in asscending order aswell.

    This solution can be optimized in a number of ways. Hint is "Xmax−Xmin<101".

    Happy Coding!!