c#, Linq
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can turn similarity into equality: two words A and B are similar if f(A) equals to f
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can turn similarity into equality: two words A and B are similar if f(A) equals to f(B) where f takes distinct characters from the word and sorts them:\n\nf(abracadabra) => abcdr\n\nthen we can group by similar words and perform a simple arithmetics\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLinq query\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n`O(n * length(word))`\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n`O(n)`\n\n# Code\n```\npublic class Solution {\n    public int SimilarPairs(string[] words) => words\n        .GroupBy(word => string.Concat(word.Distinct().OrderBy(c => c)))\n        .Sum(group => (group.Count() - 1) * group.Count() / 2);    \n}\n```
['C#']