Top 150 Interview簡単

Valid Anagram

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

問題提起

簡単

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.

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

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

解決する準備はできましたか?

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

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。