All topics
125

Same letters, different order

Tier 1Locked

Where it runs

1. The problem

Two words are anagrams if one is the other's letters put in a new order: "listen" and "silent", "eat" and "tea". This problem is the simplest way to learn the most useful string skill, counting letters. And it grows into a practical task: given a big list of words, sort them into groups so the anagrams end up together. A word-game solver does this grouping. The same move finds duplicates among records that differ only in the order of their fields.

This step is part of the paid track

The first 33 steps are open to everyone: lesson, exercise and tests. This one opens with full access. Start with a free account and the free steps.

Create a free accountSee what is included

On LeetCode

Problems that ask whether two strings use the same letters, or group words by their letters. Count the letters in a Map or an array of 26, or use the sorted letters as a signature key.

We use necessary cookies to run the site (sign-in and language). If you accept, we also load Google Analytics to see which pages are used, and Google reCAPTCHA to keep spam off the contact and bug-report forms. Privacy policy