#include <iostream>
using namespace std;
int main() {
int T,X,N;
cin>>T;
for (int i=0;i<T;i++){
cin>>N>>X;
string S;
cin>>S;
int arr[N]={};
arr[0]=X;
for(int i=0;i<(S.length());i++){
if(S[i]=='L'){
arr[i+1]=arr[i]-1;
}
else{
arr[i+1]=arr[i]+1;
}
}
int count=0;
for(int i=1;i<N+1;i++){
for(int j=0;j<i;j++){
if (arr[j]==arr[i]){
count++;
break;
}
}
}
cout<<((N+1)-count);
}
// your code goes here
return 0;
}
Why am i getting a runtime error(SIGSEGV) in in it? I am not getting any error in vs code for it. could someone explain plzz
I know the error occurs if the program is trying to take the value of an out of bound array but i have given all the necessary conditions in the program.
EDIT:- I just changed the for loop of T to while loop and it solved it.Could someone explain what just happened.