Back to Practice Dashboard
Top 150 InterviewEasy
Valid Anagram
Learn how to solve the 'Valid Anagram' problem. This detailed resource details brute force and optimized approaches.
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, typically using all the original letters exactly once.
Constraints
- •1 <= s.length, t.length <= 5 * 10^4
- •s and t consist of lowercase English letters.
Examples
Example 1
Input
s = 'anagram', t = 'nagaram'
Output
true
Example 2
Input
s = 'rat', t = 'car'
Output
false
Need a Hint?
Analyze the input constraints. Try sorting first (O(n log n)) or using a hash map/set to track seen elements in O(n) time.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.