Lesson guide
What this Python exercise practices
Check Anagrams with Frequency Arrays is a beginner practice lesson that focuses on dsa, problem patterns, edge cases. It is designed to be solved in about 8 minutes with examples, starter code, and test feedback.
Prerequisites
- Python functions
- Loops
- Lists
- Basic edge cases
Difficulty and time
- Level
- Beginner
- Estimated time
- 8 minutes
Related public exercises
Summary
Determine whether two strings are anagrams by comparing character counts.
Problem statement
Given two strings s and t, return True if t is an anagram of s. Consider all characters exactly as given (case-sensitive). Spaces and punctuation count as characters. Return False otherwise. Both inputs may be empty strings. Time complexity should be O(n).
Task
Implement a function that returns True if two input strings contain the exact same characters with the same frequencies (case-sensitive, includes spaces and punctuation).
Examples
Basic anagram
Input
s = "listen", t = "silent"
Output
True
Explanation
Both strings contain the same characters with the same counts.
Input format
Two string arguments: is_anagram(s, t)
Output format
Return a boolean: True if t is an anagram of s, otherwise False.
Constraints
0 <= len(s), len(t) <= 10^5. Use O(n) time and O(k) additional space where k is alphabet size.
Samples
Sample input 0
is_anagram("triangle", "integral")
Sample output 0
True
Explanation 0
Same characters and counts.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.