Distinct digit number 1 question of Hack cs 1.0

this is link of the question

what my approach is no of distinct numbers is much greater than number of non distinct numbers . so i am cheching for non distinct numbers in given range but problem is that
i am not getting how to get non distinct numbers greater than 1000 and less than given constraint range .

Let me explain :
There will always digits from 0 to 9 , so from iterating every no. L to R we store frq. of each digit in array of size 10 (why bcz total digits are from 0 to 9 and last index of array of length 10 is also 9)
Now in freq. array if any index value is greater than 1 than it means the digit i is repeated more than once , so we will not count that no.

bool isdiff(lli n){
lli a[10]={0};
    if(a[i]>=2) return false;
return true;

int main(){
lli t=1;
    lli n,q,f=0;
    for(lli i=n;i<=q;i++)
    if(f==0) cout<<-1<<endl;
return 0;

if u didn’t understand then tell me i will explain more :slight_smile:

i got the point we will store value of each digit in frequency array and if two or more values are same we will print -1 .than you


your welcome buddy , keep coding , we all are here to help u :slight_smile:

1 Like

thanks a lot bro ,this really motivates . i have just started “stl” and hope i will learn it fast and will be able to code like you guys up there .

god bless bro . . . . do not stop anywhere , no matter how many times u fall , u can see my profile , i travelled almost 5 7 competition in gray then many in green then blue then again green then blue then purple and now again blue , but that doesn’t mean that i stop cp , by thinking oo god merese nhi hoga :slight_smile:
Keep doing.

1 Like