1450A - Void Trygub

Since the substring “trygub” doesn’t follow a particular order character-wise, we can sort the characters in our string to force an order.

Time complexity: $O(n \log{n})$

Memory complexity: $O(n)$

Click to show code.


using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(void)
{
    ios::sync_with_stdio(false), cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        string s;
        cin >> n >> s;
        sort(begin(s), end(s));
        cout << s << endl;
    }
    return 0;
}