Ctrl K

Pairs With the Same Letter Set

Easy
You are given an array of strings tags. Call two strings alike when they use exactly the same set of letters: neither how often each letter appears nor the order of the letters matters. For instance, "noon" and "on" are alike, "note" and "tone" are alike too, but "not" and "note" are not. Count the index pairs (i, j) with i < j for which tags[i] and tags[j] are alike.
Example 1
tags=['mama', 'am', 'ma', 'stop', 'pots', 'tops', 'top'] → 6

"mama", "am" and "ma" all use the letters m and a, which gives three pairs. "stop", "pots" and "tops" all use s, t, o, p, which gives three more. "top" lacks the letter s, so it has no partner. Total: 6.

Example 2
tags=['x', 'y', 'xy'] → 0

The letter sets {x}, {y} and {x, y} are all different, so no pair qualifies.

Example 3
tags=['zz', 'z', 'zzz'] → 3

All three strings use only the letter z, so each of the three pairs counts.

Constraints
  • 1 ≤ tags.length ≤ 100
  • 1 ≤ tags[i].length ≤ 100
  • tags[i] consists of lowercase English letters only
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWords From Working Keys EasyWords From Letter Tiles EasyThe k-th Word With No Repeats EasyWords Listed Once in Both EasyMatching Sock Pairs Easy
loading Python…
Input
tags=['mama', 'am', 'ma', 'stop', 'pots', 'tops', 'top']
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.