All problems
1183EasyArrayHash TableStringBit ManipulationCounting

Pairs of Labels Using the Same Letters

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2506Count Pairs Of Similar Strings

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A shelf holds the labels labels. Two labels are alike when each uses exactly the same set of letters as the other, however many times each letter turns up in either.

Return how many pairs of positions i < j hold labels that are alike.

Examples

Example 1

Input
labels = ["abc", "cba", "bca", "acb"]
Output
6

All four labels use exactly the letters a, b and c, so all six pairs are alike.

Example 2

Input
labels = ["a", "aa", "aaa"]
Output
3

Each label uses only the letter a, however many times, so all three pairs are alike.

Example 3

Input
labels = ["ab", "cd", "ef", "ab", "cd"]
Output
2

Only the two ab labels are alike, and the two cd labels.

Constraints

  • 1 <= labels.length <= 100
  • 1 <= labels[i].length <= 100
  • each label holds only lowercase English letters

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def similar_pairs(labels: list[str]) -> int:
Java
public int similarPairs(String[] labels)
September 7
Apply