After submitting my code i am getting answer for one of the test case as 118 and itshows the expected answer to be 114, but when i am running the same code as custom input it shows the correct answer i.e 114. how is it possible?


#1
    string con(int k){
 string str1=to_string(k%2);

k=k/2;
while(k!=0){
str1=str1+to_string(k%2);
k=k/2;
}
// reverse(str1.begin(), str1.end());
return str1;
}
int Solution::hammingDistance(const vector &A) {
int x=A.size();
int temp=0;
string t;
vectorp(x);
for(int i=0;i<x;i++){
p[i]=con(A[i]);}
for(int i=0;i<x-1;i++){
for(int j=i+1;j<x;j++){
for(int l=0;l<min(p[i].length(),p[j].length());l++)
if(p[i][l]!=p[j][l])temp=temp+1;
for(int u=min(p[i].length(),p[j].length());u<max(p[i].length(),p[j].length());u++)
if((p[i][u]==‘1’)||p[j][u]==‘1’)temp++;
}
}
temp=temp*2;
return temp;
}


#2

I am also facing the same problem. If you have found the solution, could you please share it with me?


#3

in custom input it takes first element as size of array and remaining are elements of array