Day 15: Valid Anagram – JavaScript DSA Problem with Explanation
๐ Day 15 – JavaScript DSA Challenge: Valid Anagram ๐ Problem: Given two strings s and t , determine if t is an anagram of s . ๐งช Examples: Input: "anagram", "nagaram" ➡️ true Input: "rat", "car" ➡️ false ✅ Solution 1: Sort and Compare function isAnagram(s, t) { return s.split('').sort().join('') === t.split('').sort().join(''); } ✅ Solution 2: Frequency Map function isAnagramFreq(s, t) { if (s.length !== t.length) return false; const count = {}; for (let char of s) { count[char] = (count[char] || 0) + 1; } for (let char of t) { if (!count[char]) return false; count[char]--; } return true; } ๐ฏ Tips: Sorting works but is slower Hash map gives best performance for large strings ๐ Follow Me: LinkedIn: www.linkedin.com/in/reach-jaffer YouTube: @codewithjaffer