TIME LIMIT EXCEEDING

#include
#include
#include
using namespace std;

int main ()
{
int t;
cin >> t;
while (t–)
{ int n,K;
cin>>n>>K;
char *s=new char[n];
for(int i=0;i<n;i++){
cin>>s[i];
}
int *p=nullptr,*q=nullptr,countans=0;
int i, j = 0, pw, x, y;int count=0;
for (i = 0; i < strlen(s); i++)
{
if (s[i] == ‘X’)
{
p=0,q=0;
}
if(s[i]== ‘M’){
p=&i;
}
if(s[i]==‘I’){
q=&i;
}
if(p || q){
if(s[i]==’:’){
count++;
}
}
if(p && q){
pw = (K + 1) - abs(*p-*q) - count;
if(pw>0){
p=q=0;count=0;
countans++;
}
else{
p=q=0;
count=0;
}
}
}

  cout << countans<<endl;
  delete []s;

}
return 0;
}

what’s the error??

hello @samardeep

pls share ur code using cb ide.
also share the problem link with me

Problem link : https://www.codechef.com/NOV20B/problems/FEMA2

. . . . . . . . . . . . … …
save ur code here->https://ide.codingblocks.com/
and share its link

Problem link : https://www.codechef.com/NOV20B/problems/FEMA2 My code link: https://ide.codingblocks.com/s/373235

this one is live bro cant help u with it.
ask again once contest get ended.
one thing that i can comment is O(t * n) algorithm will probably fail(tle)
becuase t-> 2000 , n=100000
t*n - > 2000 * 100000 -> 2 * 10^8 which is equivalent to 2 secs (more than allowed time complexity 1sec)

we dont count no of test cases while running ?? its O(n) so i dont understand why this tle is coming

we count… . . . . (summation of time over all test cases should be less than 1sec)

. . . . . . . .

bro we don’t count no of test cases in counting the complexity of a code.

yeah complexity of an algorithm is independent from number of test cases but
in any online judge , the time limit mentioned is based on this ->

so always consider t in ur time complexity analysis for any online competetions

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.