Trains the technique from
LeetCode 2506Count Pairs Of Similar StringsThis 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.
Example 1
All four labels use exactly the letters a, b and c, so all six pairs are alike.
Example 2
Each label uses only the letter a, however many times, so all three pairs are alike.
Example 3
Only the two ab labels are alike, and the two cd labels.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def similar_pairs(labels: list[str]) -> int:public int similarPairs(String[] labels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.