Top 150 InterviewEasy

Valid Anagram

Detailed guide and Python implementation for the 'Valid Anagram' problem.

Problem Statement

Easy

Given two strings s and t, return True if t is an anagram of s, and False otherwise.

An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters exactly once.

Write a function isAnagram(s: str, t: str) -> bool.

Constraints
  • 1 <= len(s), len(t) <= 5 * 10^4
  • s and t consist of lowercase English letters

Examples

Example 1
Input
s = "anagram", t = "nagaram"
Output
True
Explanation

Both strings contain the same characters with the same frequencies: a(3), n(1), g(1), r(1), m(1).

Example 2
Input
s = "rat", t = "car"
Output
False
Explanation

'rat' contains 't' but 'car' does not. They have different character compositions.

Need a Hint?
Consider using Arrays & Hashing-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.