You are viewing a single comment's thread. Return to all comments →
Yes sure. First you calculate the no. of substrings starting from length=1 by using
for(int i=1;i<=s.length();i++)
Then you are pushing them in vector 'str' by using
for(int j=0;j+i<=s.length();j++)
By using this below logic you are comparing two strings in str vector for anagrams and maintaining the count.
for(int p=0;p<str.size();p++) for(int q=p+1;q<str.size();q++)
Then again the same procedure for length=2, length=3 till length =string`s length-1.
Hope you got it.
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 →
Yes sure. First you calculate the no. of substrings starting from length=1 by using
Then you are pushing them in vector 'str' by using
By using this below logic you are comparing two strings in str vector for anagrams and maintaining the count.
Then again the same procedure for length=2, length=3 till length =string`s length-1.
Hope you got it.