A key must separate
transcript
A key can join the right items. It can also join the wrong ones. Take the sum of the letter codes as a key. It looks fine on small tests. It is wrong.
The words ad and bc both sum to one hundred ninety-seven. They land in one group, and they are not anagrams. Sorted letters keep them apart.
For rotations, sorted letters join abc and acb. But acb is no rotation of abc. The smallest rotation keeps them apart.
Test two items that are almost the same kind. Test two equal items. They must join. Test one tiny item, such as a single letter.
A weak key hides in small tests. Small examples rarely collide. Real inputs have thousands of items. Collisions then appear. So test the key on near neighbours before you code.
A key joins every member. It also separates other groups. The right key depends on the rule. Full breakdown in the lecture.