Friday, September 15, 2006

Repeated Digits

Given a number with n digits.
Find whether there are repeated digits in that number.

If n > 10, return true //there are repeated digits
if n <= 10, we can create an array of size 10 and record number of entries...this wont need many resources...

2 comments:

Rahul said...

I am not changing the problems concept

but in both case complexity will be O(10)
at least loop to count n

and when we are doing it for n<10 simple count sort will work

Anonymous said...

int main(int argc, char* argv[])
{
int a = 2235562, mod,i;
int dup[10]={0};

do{
mod = a %10;
dup[mod]++;
a/=10;

}while(a !=0);

for(i=0;i<10;i++){
if(dup[i]>1){
printf("%d \n",i);
}
}


printf("Done!\n");
return 0;
}