Help with DISCHAR Problem !!

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?

hey @thebenman, your code is giving wrong answer on test case aaabaaab
your code gives output 4 but the correct answer should be 2.

Another example is aaababcabcaaab correct answer is 3, your code gives 5. I think these cases will help you correct your solution. :slight_smile:

@thebenman
The problem here itself says it all.
You need to find the number of distinct characters in the input string.