Your program should determine how many anagrams exist in a given string and return the total number. For example: if str is "aa aa odg dog gdo" then your program should return 2 because 'dog' and 'gdo' are anagrams of 'odg'. The word 'aa' occurs twice in the string but it isn't an anagram because it is the same word just repeated. The string will contain only spaces and lowercase letters, no punctuation, numbers, or uppercase letters.
Expert in Data Structures & Algorithms. Building tools to help developers crack FAANG interviews.