Why my code not working for second test case?

Hi Deepanshu
Your code is fine. Just initialize the prefix array inside main as:
for(int i=0;i<10000005;i++)
prefix[i]=0;
Rather than doing it the way you have done. Try using above way of initializing array as much as you can because assigning {0} to the whole thing doesn’t work everytime.