On putting input getting the right output......but still WA.please help


check for edge cases
given sample inputs usually are simple

5-stars aap par bohot badhiya lag rahe hai.Congratulations :heart_eyes::smiling_face_with_three_hearts:

couldn’t find any…please help

There is issue with your code.

Error 1 : You have mistake in taking input

Given the limit of N is (1 <= “N” <= 1000)
This means in next line you can have a string with 1000 characters (i.e 1000000000…0000000…0000) , but you have declared a variable “r” as long which cannot hold the value as max value of long is 2147483648 i.t around 10 digits .

I hope you understood the issue.

                 int n=Integer.parseInt(br.readLine());
	     **long r=Long.parseLong(br.readLine());**
	        long a[]=new long[n];
	        for(int i=n-1;i>=0;i--)

You can use something like this. Take a string as input then feed the same into array.

        String s=br.readLine();
        String[] strs = s.trim().split("");
        int a[]=new int[strs.length];
        int l=strs.length;
        for (int i = 0; i <l ; i++) {
            a[i] = Integer.parseInt(strs[i]);

Error 2 : You also missed an edge case when n==1 , Your program fails
int count=0;
//Your code logic to increment count

Happy to Help 3000 . :slight_smile:

1 Like