Given two strings s and t, determine if t is an anagram of s — that is, whether t can be formed by rearranging every character of s exactly once, using each character the same number of times.
s = "anagram", t = "nagaram"trues = "rat", t = "car"falseTry it now — no sign-up needed. Write your solution in Python or JavaScript, run it against test cases, and submit for a verdict, right in your browser.
Open the editor →Arrays give O(1) index access; hash maps and sets give O(1) average lookup, insert, and delete by trading space for speed. Together they're the toolkit for turning brute-force O(n²) comparisons into a single O(n) pass.
Read the full Arrays & Hashing guide →
Original problem on LeetCode ↗