MAX 2 PROBLEM IN PRACTICE SECTION

Dear supercoders,
can anyone tell why i getting wronganswer while submitting, instead of getting correct output with every testcase.plzzz provide details of why i getting this problem.
I getting accurate answer in online java compiler also.

AND MY SOLUTION LINK AS FOLLOWS

Https://www.codechef.com/viewsolution/24116425

AND MY CODE IS AS FOLLOWS

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try{
int N,i,j,k,smpl,val=0,fnlval=0;
String str;
Scanner sc=new Scanner(System.in);
// System.out.println(“enter size”);
N=sc.nextInt();
sc.nextLine();
StringBuffer sb=new StringBuffer(N);
str=sc.nextLine();
sb.append(str);
//len=sb.length();
for(i=N-1,j=0;i>=0;i–,j++)
{
char c=sb.charAt(i);
smpl=Character.getNumericValue©;
// System.out.println("smpl is "+smpl);

       val=val+((int)Math.pow(2,j)*smpl);
        //System.out.println(" inside val is "+val);
   }
    // System.out.println("val is "+val);
   for(i=N-1,j=0;i>=0;i--,j++)
   {
       if((j>fnlval)&&(val%(int)Math.pow(2,j)==0))
       {
           
           fnlval=j;
            //System.out.println(" inside fnlval is "+fnlval);
       }
   }
     System.out.println(fnlval);
 
  //  System.out.println("2power5 "+(int)Math.pow(2,5));
   
    //System.out.println("Sum of x+y = " + z);
    }catch(Exception e){return;}
}

}

Just check the first set bit from right and the index(0- indexing) at which it occurs is the ans.

1 Like

Bro sorry if you dont mine can you read question clearly because i though you misunderstood the question .And give reply clearly broo

@shammumax1999 I think you have not properly understood the question.
You are required to find the highest power of 2 i.e if a number N is divisible by 2^x then the answer would be x. So the solution reduces to find the first set bit from the end or right hand side.
Eg:
7
1010000
We can see that the first set bit occurs at 4 (0 based indexing)

Code : https://www.codechef.com/viewsolution/24130524

Then my program also printing 4((2^4)=16 which is divisor of 80.so it prints highest power (2^4) and divisor of 80 which is 4) for your sample testcase.broo can you check if you dont mine .and plzzzz reply

Luckily i found a test case, you need to fix some bugs
INPUT:
80
11111111111111111111111111111111111111111111111111111111111111111111111111111111
Expected O/P : 0
Your O/P : 1
Also try ,
70
1111111111111111111111111111111111111111111111111111111111111111111111
Expected O/P : 0
Your O/P : 3

Tnq sooo much Bro
For your kind information