Someone help me to find out the mistake

amazon
Tags: #<Tag:0x00007f2425b9e240>

#1
int Solution::power(string A) {
long long int j,l=A.length(),n=0;
double i=0;
for(j=0;j<l;j++)
{
    n=n*10+(A[j]-'0');
}
i=n;
while(i>1024)
{
    i=i/1024;
    //cnt++;
}
//return i;
//i=n;
//cnt=cnt*10;
if(i==2)
{
    return 1;
}
if(i==4)
{
    return 1;
}
if(i==8)
{
    return 1;
}
if(i==16)
{
    return 1;
}
if(i==32)
{
    return 1;
}
if(i==64)
{
    return 1;
}
if(i==128)
{
    return 1;
}
if(i==256)
{
    return 1;
}
if(i==512)
{
    return 1;
}
if(i==1024)
{
    return 1;
}
return 0;

}


#2

What’s wrong in this code


#3

You are Converting the string input to a long long int, when it is cearly mentioned in the problem statement that the string inputs integer counterpart will exceed 2^64 so your n will overflow and give wrong output.


#4

You can try this: