My code works correctly for the test case stated in the problem though.
Here is my work: http://ideone.com/fXLM6u
Since i can’t figure out what might have caused an NZEC,it would be extremely helpful if anyone could figure it out and let me know the reason behind it.
Thank You.
All the accepted JAVA solutions are within the memory limit of 256 MB, while your solution takes around 380 MB, I’d suggest changing your approach of taking string input or changing your programming language to C, C++. JAVA has a substantial overhead of around 178 MB due to its libraries which also makes it a little slow.
However, this problem doesn’t require large amount of memory as the constraints are very small.