Anagram
Anagram
An anagram is a word formed by rearranging the letters of another word, using all the original letters exactly once. For example, the word anagram itself can be rearranged into nagaram, also the word binary into brainy and the word adobe into abode.
Valid Anagram
Given two strings
s
andt
, how do we check whether they are anagrams of each other?
One way is to sort both strings lexicographically and compare the sorted strings:


This runs in O(nlogn)
time and O(n) space
.
Can we do better? If the letters in s
and t
are lowercase English letters, then we can simply store the frequency of each letter.


Or


The last two frequencybased implementations have linear time complexity and constant space complexity.
Minimum Number of Steps to Make Two Strings Anagram
Given two equalsize strings
s
andt
. In one step you can choose any character oft
and replace it with another character.Return the minimum number of steps to make
t
an anagram ofs
.
Solution:


Find All Anagrams in a String
Given two strings
s
andp
, return an array of all the start indices ofp
's anagrams ins
.
Solution:


Group Anagrams
Given an array of strings
strs
, group the anagrams together.
Solution:

