You are given two strings, word1 and word2.
Your task is to determine if word2 is an anagram of word1. An anagram is formed by rearranging the letters of one word to produce another, using each letter exactly once.
You may assume that:
word1 and word2 will contain only lowercase English letters.word1 nor word2 will include any spaces.Return true if word2 is an anagram of word1, and false otherwise.
word1 = "listen"
word2 = "silent"
True
Both words use the same characters with the same frequency. 'silent' is a rearrangement of 'listen'.
word1 = "hello"
word2 = "world"
False
The words have different characters and lengths.
word1 = "house"
word2 = "hoe"
False
'house' contains all letters of 'hoe', but 'hoe' is only a subset, not a full anagram.
word1 = "listen"
word2 = "silent"
True