Why am i getting runtime SIGSEGV error even when my solution is right and has been aceped

so the link to my problem : https://www.codechef.com/problems/STRCH

when i submitted my piece of code it got accepted but when ran a simple run i got this runtime error

my code is here :

#include <iostream>
#include <string>
#define ll long long int
using namespace std;

int main() {
    int T;
    cin>>T;
    while (T--){
        ll N;
        cin>>N;
        string s;
        char X;
        ll Total = (N * (N+1)/2);
        cin>>s>>X;
        ll last = -1;
        s +=X;
        for (int i =0; i<=N; ++i){
            if(s[i] == X){
                ll len = i -last-1 ;
                Total-= (len*(len+1))/2;
                last = i;
            }
        }

        cout<<Total<<"\n";
        
    }    // testases end over here
    
    return 0;
    
}

Are you trying to “Run” without Providing “Custom Input”?

2 Likes

yes…
thnx for the quick reply though :grin:

an you help me with this ???

You need to click custom input and then put in valid test data for it to work.

i didnt understand your logic ?
when i ran my custom tests with the inputs given in the question; i got the correct outputs but when i unchecked 'Custom Input ’ option and then ran the code i got this runtime error.

i have solved some other problems as well but this hasn’t been noticed while i was doing those qustions. So why this time i got the runtime error ?

When you uncheck custom input, you are not running on the sample test cases, but empty input.

Did you read the link in my original reply?

1 Like

srry didn’t notice it

1 Like