Facebook Pixel

Valid Anagram

Given two strings s and t, determine if t is an anagram of s. An anagram is formed by rearranging the letters of a word using all the original letters exactly once.

Input

  • s: a string
  • t: a string

Output

A boolean - true if t is an anagram of s, false otherwise

Examples

Example 1:

Input: s = "listen", t = "silent"

Output: true

Explanation: Both strings contain the same characters with the same frequencies: l(1), i(1), s(1), t(1), e(1), n(1).

Example 2:

Input: s = "hello", t = "world"

Output: false

Explanation: The strings contain different characters.

Example 3:

Input: s = "aab", t = "aba"

Output: true

Explanation: Both strings contain a(2), b(1).

Example 4:

Input: s = "rat", t = "car"

Output: false

Explanation: Different character frequencies - s has r(1), a(1), t(1) while t has c(1), a(1), r(1).

Try It Yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro