Valid Anagram - aloalgo

Valid Anagram

Easy

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:

  • Both word1 and word2 will contain only lowercase English letters.
  • Neither word1 nor word2 will include any spaces.

Return true if word2 is an anagram of word1, and false otherwise.

Example 1

Inputs
word1 = "listen"
word2 = "silent"
Output
True
Explanation:

Both words use the same characters with the same frequency. 'silent' is a rearrangement of 'listen'.

Example 2

Inputs
word1 = "hello"
word2 = "world"
Output
False
Explanation:

The words have different characters and lengths.

Example 3

Inputs
word1 = "house"
word2 = "hoe"
Output
False
Explanation:

'house' contains all letters of 'hoe', but 'hoe' is only a subset, not a full anagram.

Loading...
Inputs
word1 = "listen"
word2 = "silent"
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!