➤ Problem Link : 1348C. Phoenix and Distribution
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
string s;
cin>>s;
sort(s.begin(),s.end());
if(k==1)
{
cout<<s<<"\n";
continue;
}
if(s[0]!=s[k-1] || k==n)
{
cout<<s[k-1]<<"\n";
continue;
}
if(s[k]!=s[n-1])
{
cout<<s.substr(k-1)<<"\n";
continue;
}
int l=n-k;
if(l%k==0)
l/=k;
else
l=l/k+1;
cout<<s[0];
for(int i=0;i<l;i++)
cout<<s[n-1];
cout<<"\n";
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
