I was solving a question this is my code its working perfect on my local Work space with the below input and gives the expected output but in hacker rank it is a time out for compilation .
The problem statement is In the given string:
occurs two times. and occur one time each.
The remaining digits and don't occur at all.
Sample Input 1: lw4n88j12n1
Sample Output 1 : 0 2 1 0 1 0 0 0 2 0
Facing Issue with below input
Input:
9139f793308o0lo66h6vc13lgc697h0f6c32lu84445972k0o0l033od17c083yn5051d6j319hyo8j939n28d913015ns6zx5653x01211x12ch2526o65sg7xw6302141q9203s22l336319ll9yx4b597mr318a7943906750j4u152067nq83ne9f24thu96yd05173l47c803roxci45615f0w53i1sz913jj6za733l73tw6r66mq6p44sfhjr26h8e801z8zlcx2l1e65r2879xj3w3acv216196uq158o663y7oz2i5378v0v5w17762451t424352m23026r9o202i9785382o159e4gu1c8561157z5f1vqs5755465b8u728u956434mv944885li456628a994u7j5278m269n1pk8e46940q834h06il6h447888tr7ig72z10fe09k5g98h9bgt6z40v42s16pt6k3l3v45i83i01b9448g554741w766f2q7v31i085488h060e710p53076c6nm98pi946g8j2n6j8x29qa1ad48172y0u4818121p686bud89741201p54087u56g8scerv9pvhuo09re477zfb224i2c1325bj58jx4bk7b009f6446j5i95474p266i503r670n631x6940gwl71ejbx47imx576129248901765rnpu6l80084t0j1839f5y3409w2n403fu6ogw1170jmb6o5l520vg0703e0
Expected Output: 53 54 47 48 54 52 63 46 49 46
Thanks for the help in advance.
int main() {
int i;
int value;
char x;
int arr[10] = {0};
char * ptr =(char *)malloc(sizeof(char *));
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
scanf("%s",ptr);
while(*ptr != '\0')
{
if(*ptr >= 65 && *ptr <=90 || *ptr >=97 && *ptr <=122){
*ptr++;
}
else{
x = *ptr;
value = atoi(&x);
switch (value)
{
case 0:
arr[0]++;
*ptr++;
break;
case 1:
arr[1]++;
*ptr++;
break;
case 2:
arr[2]++;
*ptr++;
break;
case 3:
arr[3]++;
*ptr++;
break;
case 4:
arr[4]++;
*ptr++;
break;
case 5:
arr[5]++;
*ptr++;
break;
case 6:
arr[6]++;
*ptr++;
break;
case 7:
arr[7]++;
*ptr++;
break;
case 8:
arr[8]++;
*ptr++;
break;
case 9:
arr[9]++;
*ptr++;
break;
}
}
}
for(i=0;i<=9;i++)
{
printf("%d ",arr[i]);
}
return 0;
}