I have been given programming assignment on which I have got stuck. Its Description is as follows:
There is a game named Secret Santa (who gives them gifts) where number of kids participate. For Every participating kid there is a Secret Santa friend from the participating kids. I have to write a program that selects a Secret Santa friend for every participating kid.
Example:
IF Bob, Alice , John and George are participating kids, After random selection the
output may look like
Kid Secret Santa
Bob ---------- John
Alice--------- Bob
George-------- Alice
John---------- George
Two consecutive runs of the program with same inputs should not have same results.
My idea is: (C based implementation)
- Input the Number of participating students and then store them in an Array.
- Then form another Array of Integers , size equal to number of participating kids.
- Shuffle the Integer Array.
- Then iterate through both the Arrays to find them the match.
Would this be the right way to do? it will waste an extra space of the Integer Array. Can Anyone help me find a more efficient solution (minimize space utilization).