Array search problem

Hi,
I have been given a problem and I just can’t manage to get even close to the solution. I have tried some for loops with if…else statements, but did not do the trick. I am not very good with functions, so I haven’t tried with it. Here is the task:

Given an array of integers, some elements appear twice and others appear once. Each integer is in the range of [1, N], where N is the number of elements in the array.
Find all the integers of [1, N] inclusive that do NOT appear in this array.
Input - Read from the standard input:
There is one line of input, containing N amount of integers, separated by a comma (“,”)
Output - Print to the standard output:
There is one line of output, containing the sorted integers, seperated by a comma (“,”)
Constraints - N will always be in the range of [5, 1000]
Sample Tests
Input Copy - 1,2,3,3,5
Output Copy - 4

Input Copy - 4,3,2,7,8,2,3,1
Output Copy - 5,6

Input Copy - 1,1,1,1,1,1,1,1
Output Copy - 2,3,4,5,6,7,8

If someone can give any advice how to begin or what pattern I should follow, that would be great. :slight_smile:

I really suggest you try to write pseudocode to solve this

how would you go at it if you had to solve it with pen and paper?

Well, from what I thought so far is to compare the given input(array) with one made from me based on the length of the given input. For example:
if we have an input of length 8 to make an array from 1 to 8. In this way I can compare what is missing from the input based on the made up array.

Hi,

  • build an array from the input
  • build an empty array for the output
  • make an iteration from 1 till input length (this is the index)
  • if the index is not in the input array, then add this index to the output.

Now just build a function from the above steps.

If you choose the other side and at the second step build an array from 1 till input length then the code will be more difficult. Easier to start with empty array…