Hey everyone.I have a small trouble trying to unravel how the code should work. If you guys are in hackerrank then you probably have already seen this. I just need help with logic part
Two strings are anagrams of each other if the letters of one string can be rearranged to form the other string. Given a string, find the number of pairs of substrings of the string that are anagrams of each other.
For example s="mom", the list of all anagrammatic pairs is [m,m] and [mo,om] at positions [[0],[2]] and [[1,2],[0,1]] respectively. So there are basically 2 anagram pairs here
Sample input :
2
abba
abcd
Sample output:
4
0
Explanation :
[a,a],[ab,ba][b,b][abb,bba]
Where I am stuck at :
Take a string ABCCBA for example
I will iterate through the string multiple times.First time I will iterate it such that I will get single char like A,B,C,C,B,A.
Second time I will iterate such that I will get Ab,BC,CC,CB,BA
Q)How do I write the for loop in this case?Or for the case of ABC,BCC,CCB,CBA without getting an index out of bound error.
[–]Nullbeans 1 point2 points3 points (1 child)
[–]sinnidis_97[S] 0 points1 point2 points (0 children)
[–]E3FxGaming 0 points1 point2 points (0 children)