2

Given an array[n] containing all numbers from 1-n ( both inclusive) distributed randomly, but missing two random numbers from this range. This means either a single number has been repeated thrice, or two numbers have been repeated twice.

For ex: Array[100] contains number from 1-100 but missing any two numbers.

Devise a method to find the missing two numbers in minimum number of hits, given (n) and array[n]

Anathema.Imbued
  • 3,271
  • 4
  • 17
  • 18
  • I'm beyond that age to ask homework problems, ok ? – Anathema.Imbued Sep 13 '13 at 05:28
  • My apologies. It would be helpful, however, to describe your current ideas or what you have tried so far. – idfah Sep 13 '13 at 05:39
  • Here's a good place to start: http://www.geeksforgeeks.org/find-a-repeating-and-a-missing-number/ – Jim Mischel Sep 13 '13 at 15:32
  • Also, check the related questions on the right. For example, the answers to http://stackoverflow.com/questions/3492302/easy-interview-question-got-harder-given-numbers-1-100-find-the-missing-numbe?rq=1 have lots of good links. – Jim Mischel Sep 13 '13 at 15:33

1 Answers1

2

An array of bool[100], where element[i] is true if i is found in your original array. Or you can use some kind of hashtable. In both cases you will find missing numbers in one go.

athabaska
  • 455
  • 3
  • 22
  • Oh btw if you use array of int instead of bool, you can have an amount of each number met in original array. – athabaska Sep 13 '13 at 05:38