HTML & JS
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define F first
#define S second
#define all(c) (c).begin(), (c).end()

int tc;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> tc;
    while (tc--)
    {
        int n;
        string s;
        cin >> n >> s;

        bool flag = true;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'W')
                continue;
            else
            {
                int j = i, cr = 0, cb = 0;
                while (j < n && s[j] != 'W')
                {
                    if (s[j] == 'R')
                        cr++;
                    else if (s[j] == 'B')
                        cb++;

                    j++;
                }

                if (cr == 0 || cb == 0)
                {
                    flag = false;
                }

                i = j - 1;
            }
        }

        if (flag)
            cout << "YES\n";
        else
            cout << "NO\n";
    }

    return 0;
}

Generated URL:

Output:

No Output
Report Bug