Problem Statement ;[CodeChef: Practical coding for everyone]
My approach to this problem seems to be correct, but getting Run Time Error .
Can someone help me where the below code went wrong to throw Runtime Error.
static long playGame(int ini, int n, int q) {
long headctr = 0, tailCtr = 0;
char[] charr = new char[n];
if(ini == 1)
Arrays.fill(charr,‘H’);
else
Arrays.fill(charr,‘T’);
for(int i=0; i<n; i++) {
for(int j=0; j<=i; j++) {
if(charr[j] == ‘H’)
charr[j] = ‘T’;
else
charr[j] = ‘H’;
}
}
for(int i=0; i<charr.length; i++) {
if(charr[i] == ‘H’) headctr++;
else tailCtr++;
}
return (q==1)?headctr:tailCtr;
}
Thanks