0

I have a 2D array: (int[,] sz = new int[52, 5];) filled with int32s (all of them is between 1 and 90). I need to decide if there is at least one number between 1 and 90, that is not contained in the array.I only need a yes or no answer.

I tried with Array.Exists, but it didn't work (I probably didn't use it properly).

I'm looking for the most simple solution (just started recently, I'm far from expert), and I would apreciate a little help :)

randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72
zatu
  • 13
  • 1

1 Answers1

0

You can create a boolean array of 90 positions, initialized to False.

Then, you go through the 2D array and mark True on the positions of the first array if the number is between 1 and 90. Careful: positions on arrays are usually from 0 to 89.

Finally, you can search in the boolean array if it is some False value, indicating that a value does not exists in the 2D array.

The question is a common exercise, similar to:

Find an integer not among four billion given ones

Community
  • 1
  • 1
robermorales
  • 3,293
  • 2
  • 27
  • 36