/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        string s;
        cin>>n;
        cin>>s;
        map<char,vector<int>> mp;
        int f=0;
        for(int i=0;i<n-1;i++){
            if(s[i]==s[i+1]) f++;
            else{
                if(i==n-2 && s[n-1]==s[n-2]) f++; 
                mp[s[i]].push_back(f+1);
                f=0;
            }
        }
        int arr[26]={0};
        for(auto it=mp.begin();it!=mp.end();it++){
            arr[it->first-'a']=*min_element(it->second.begin(),it->second.end());
        }
        for(int i=0;i<26;i++){
            cout<<arr[i]<<" ";
        }
    }
    

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: