I'm trying to write a recursive function to find duplicates in an array of integers. For example if the array is: {4, 1, 4, 3, 2, 3} it should returns 2. I tried a mergesort-like approach but without success. Someone can help?
My try (works only with ordered arrays):
int count(int arr[], int bot, int top){
if(bot==top) return 0;
else{
int med = (bot+top)/2;
int n = count(arr, bot, med) + count(arr, med+1, top);
if(arr[med]==arr[med+1]) n++;
return n;
}
}