Ans is coming wrong

#include
#include<bits/stdc++.h>
using namespace std;
int gates(char arr[],int n,int k)
{
int count=0;
int j=n-1;
while(k–)
{
if(arr[j]==‘H’)
{
count++;
}
j–;
}
int ans=0;
char c;
if(count%2==0)
{
c=‘H’;
}
else
{
c=‘T’;
}
for(int i=0;i<=j;i++)
{
if(arr[i]==c)
{
ans++;
}
}
return ans;
}
int main()
{
int t;
cin>>t;
while(t–)
{
int n,k;
cin>>n>>k;
char arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
cout<<gates(arr,n,k)<<endl;
}
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Also - what Problem are you trying to solve? :slight_smile:

He is trying to solve the first problem of Division2 FebruaryLunchTime.