I tried to approach this problem by subtracting those substrings which do not have the required character from the total no of substrings.I am getting correct answers for every test case I can come up with but still getting WA for some test cases.Can anyone identify what I am doing wrong?
My code is provided here : STRCH
It’s an overflow.
At line 6, you’re casting N(N+1) to long after the multiplication.
You gotta cast N first like (long)N * (N+1) / 2
@creep04
Can you please help me, I’m getting WA for some test cases, I tried many test cases manually I’m getting correct answer for them, can anyone tell me what is wrong with my code https://www.codechef.com/viewsolution/23947768
@sahil9420 can you please assist me with solution

scanf("%lld",&n);long long int n,i,vikky=0,l=0;
//printf("%lld\n",n);
char kiran[n],p;
scanf("%s %c",kiran,&p);
// printf("%s %c\n",kiran,p);
for(i=0;i<n;i++){
char pp=kiran[i];
if(pp==p){
l=i+1;
}
vikky=vikky+l;
}
printf("%lld\n",vikky);
why it assign i+1 to l and increcment vikky by l

long su(long n) { return (n*(n+1))/2; }
scanf("%ld",&n);
char a[n];
getchar();
scanf("%s",a);
char x;
getchar();
scanf("%c",&x);
long z=su(n);
long c=0;
for(int i=0;i<n;i++)
{
if(a[i]!=x)
c++;else { z=zsu(c); c=0; }
}
z=zsu©;
printf("%ld\n",z);
it always minus the sum when char is not required and put again c=0
please specify the logic
any other logic is also appreciated