➤ Problem Link : 1278A. Shuffle Hashing
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string p,h; cin>>p>>h; int l=p.length(); int hl=h.length(); int phash[257]; memset(phash,0,sizeof(phash)); for(int i=0;i<p.length();i++) phash[p[i]]++; bool flag=1; for(int i=0;i<=hl-l;i++) { int hash[257]={0}; for(int j=0;j<l;j++) { hash[h[i+j]]++; } flag=0; for(int j=0;j<257;j++) { if(hash[j]!=phash[j]) { flag=1; break; } } if(!flag) { cout<<"YES\n"; break; } } if(flag==1) cout<<"NO\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!!