My issue
1
26
aabccbbbccaacacccbbaacbacb
What shall be the answer for this test case?
My code
#include <bits/stdc++.h>
using namespace std;
// Aliases
using ll = long long;
using lld = long double;
using ull = unsigned long long;
// Constants
const lld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll mod = 1000000007;
#define debug(x) cerr << #x << " " << x << endl;
#define cy cout << "YES\n"
#define cn cout << "NO\n"
void testcase()
{
int n;
cin >> n;
string s;
cin >> s;
int a = 0;
int b = 0;
int c = 0;
int count = 0;
for (int i = 0; i < n; i++)
{
if (s[i] == 'a')
a++;
if (s[i] == 'b' && a > 0)
b=a;
else if (s[i] == 'c' && b > 0 && a > 0)
{
count++;
a--;
b--;
}
}
cout << count << '\n';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
testcase();
}
return 0;
}
Problem Link: ABC Conjecture 3 Practice Coding Problem - CodeChef