➤ Problem Link : SORTOUT
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,q;
cin>>n>>q;
string str[n];
for(int i=0;i<n;i++)
cin>>str[i];
sort(str,str+n);
string s;
int low,mid,high;
while(q--)
{
cin>>s;
if(str[0]>s)
cout<<"0"<<"\n";
else
{
low=0;
high=n-1;
mid;
while(low<high)
{
mid=low+(high-low+1)/2;
if(str[mid]<=s)
low=mid;
else
high=mid-1;
}
cout<<high+1<<"\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!!
