Ankit_132

B

Nov 25th, 2023
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  6.  
  7. int main()
  8. {
  9.     _test
  10.     {              
  11.         int n;
  12.         cin >> n;
  13.         string s;
  14.         cin >> s;
  15.         int mn = n, mx = 0;
  16.         for (int i = 0; i < n; i++) {
  17.             if (s[i] == 'A') mn = min(mn, i);
  18.             else mx = i;
  19.         }
  20.  
  21.         cout << max(0, mx - mn) << "\n";
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment