Count anagram-based replacements per phrase | Oracle Interview Question