you have an array of the Doc class which has a DocIndex property, for which the property is not set, some elements of the array may be null
//*** small version of the Doc class, just for the puzzle
class Doc {
public int docIndex;
}
Doc[] docs = new Doc[] { new Doc(), new null, null, new Doc() };
then you have an array of ints that represent the indexes that are already taken, e.g.
new int[] { 2, 3, 5, 7, 9 }
your job is to assign the indexes to the Doc[] that are not "taken" (exist in the array)
so, for these examples:
The expected output would be:
existing :
2 3 5 7 9
docs :
0 1 4 6 8
existing :
0 1 2 3 4
docs :
5 6 7 8 9
existing :
5 6 7 8 9
docs :
0 1 2 3 4
what do you think of this problem for a code interview?