Find the number that is repeating from distinct random numbers.
Example: 3, 4, 8, 6, 7, 9, 4, 77 Ans = 4
Solution:
This problem can easily be solved by using hashtable
We put the elements of the array in hashtable and check if we already put the number if so we will return the number
Hashtable ht = new Hashtable();
for (int i = 0; i < a.Length; i++) {
if (!ht.ContainsKey(a[i]))
ht.Add(a[i],0);
else
return a[i];
}