Sequence NODE_151
MediumCheck if Two Strings Are Anagrams
JavaScript
Technical Specification
Check if two given strings are anagrams of each other (same characters with same frequency).
Input/Output Samples
Input:"listen", "silent"
Output:true
Input:"hello", "world"
Output:false
Optimal Logic Path
function areAnagrams(a, b) {
const normalize = (s) =>
s.toLowerCase().replace(/[^a-z0-9]/g, "").split("").sort().join("");
return normalize(a) === normalize(b);
}Architectural Deep-Dive
We normalize both strings by cleaning and sorting their characters; if they match, they’re anagrams.