Facing a Runtime Error for First Test case in Second Set for the Problem "PINBS"

I tried the problem in java as well as Python with the same logic.
The Python solution got accepted but Java one doesn’t. I have a standard template for my java solutions which I use for Fast I/O and some basic Utilities(Which is anyways not used in this solution).
Can anyone look and help that would actually be a great help.
Thanks in advance :slight_smile:
Problem Link: Prime in a binary string
My Java Solution: Java
Python Solution: Python

Crashes on this testcase.

                if (cnt != 0) /*<-- Hmmm. */{ 
                        break;
                    }
                    else {
                       continue; 
                    }
                }
                buf[cnt++] = (byte)c;
                if(cnt == buffLen) {
                    toReturn.append(new String(buf, 0, cnt));
                    cnt = 0; // <-- Yikes!
2 Likes

Hi, Huge thanks for the reply and sorry for the late reply I didn’t get any notifications so I was not aware someone did reply.
I tried running the test case you suggested, It didn’t break for me, I got YES as output for all of them.
I am making cnt(The current buffer length) as 0 indicating I don’t have a buffer now.
Could you please be more precise about how it breaks?

Thanks

If I run that testcase through this solution, I get:

[simon@simon-laptop][16:20:16]
[~/devel/hackerrank/otherpeoples]>cat PINBS-testcase.txt | ./run-java.sh 
YES
NO
YES
YES
YES
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 65536 out of bounds for length 65536
        at Main$Reader.read(theflash123-PINBS.java:127)
        at Main$Reader.readLine(theflash123-PINBS.java:33)
        at Main.main(theflash123-PINBS.java:189)

Yeah I got the Error, Any idea how do I solve it?
Because the reason I used this Reader class, is because Bufferred Reader was a bit slow for some platforms.

Just replace all this:

                    if (cnt != 0) {
                        break;
                    }
                    else {
                        continue;
                    }

with

                    break;

If you really, really want to ignore empty lines, fix the logic!

Alright, will do Thanks for th Help

1 Like