✅ Aesthetic & Very Simple TypeScript Solution (O(N))
\n\n# Intutiton\n- Instead of comparing each word, we can jus get the unique sorted alphabets and count them for the given words so that we can do O(N) instead 
\n\n# Intutiton\n- Instead of comparing each word, we can jus get the unique sorted alphabets and count them for the given words so that we can do O(N) instead of O(N * N)\n\n# Code\n- prepare `getCode()` function that returns code of word.\n    - "Code" here is defined as a string with unique sorted alphabets\n    - i.e) ab\n    - i,e) de\n    - NOT ed (not sorted)\n    - NOT aab (not unique)\n- prepare `getTotalPairs()` function that returns the total count of the same code (Detailed explain below)\n    - ![image.png](https://assets.leetcode.com/users/images/cd013846-56d5-45d2-a225-2dbb914f4f7d_1685054333.8837683.png)\n    - ![image.png](https://assets.leetcode.com/users/images/ff3632bf-5441-442c-b7e3-eade14a91cf3_1685054399.2597115.png)\n    - Do you see the pattern here?\n    - ![image.png](https://assets.leetcode.com/users/images/f0a8ca2d-ad61-4e78-8950-4600f01ba261_1685054447.0269556.png)\n- The main function:\n    - Loop through each word and get the code with the `getCode()` and we will count each total number of each code\n    - Then we can figure out the total pairs of the each count with the `getTotalPairs()`\n    - Return the `totalPairs`\n\n```ts\nconst getCode = (word: string): string => { // O(N)\n    const set = new Set<string>()\n    for (const c of word) set.add(c)\n    return Array.from(set).sort().join()\n}\n\nconst getTotalPairs = (n: number) => (n * n - n) / 2\n\nfunction similarPairs(words: string[]): number {\n    const map = new Map<string, number>()\n    words.forEach(word => { // O(N)\n        const code = getCode(word)\n        map.set(code, (map.get(code) || 0) + 1)\n    })\n\n    let totalPairs = 0\n    map.forEach((count) => totalPairs += getTotalPairs(count)) // O(N)\n    return totalPairs\n}\n```
['TypeScript']