You are viewing a single comment's thread. Return to all comments →
Well, what I learnt is we should always try brute first before letting the question question our own existence.
My simple c++ brute sol:
#define ll int #define all(a) a.begin(),a.end() void solve(){ string s,p; cin>>s; ll n=s.length(),c=0; for(ll i=1;i<n;i++){ map<string,ll> mp; for(ll j=0;j<n-i+1;j++){ p=s.substr(j,i); sort(all(p)); mp[p]++; } for(auto x:mp){ if(x.second>1){ c+=(x.second-1)*(x.second)/2; } } } cout<<c<<endl; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
Well, what I learnt is we should always try brute first before letting the question question our own existence.
My simple c++ brute sol: