Hey,
The link to the question is http://www.codechef.com/problems/DISCHAR
I was trying to solve this relatively easy looking problem. But, it gives me WA for all the cases.
The code is here
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX(a,b) ((a)>(b))? a:b
int main()
{
int testCases;
int i,j;
char *string = (char *)malloc(sizeof(char) *100000);
scanf("%d ",&testCases);
while(testCases--)
{
int max=0,great =0;
scanf(" %s",string);
int length = strlen(string);
printf("%d\n",length);
printf("%c\n",string[5]);
for(i=0;i<length;i++)
{
for(j=i+1;j<length;j++)
{
if(string[i] == string[j])
{
break;
}
}
//printf("%d %d\n",i,j);
max = j-i;
if(max>great)
great = max;
}
printf("%d\n",great);
}
return 0;
}
Could you help with finding where the problem lies?