Arrays & Hashing/Easy

Valid AnagramPRO PASS

Time: O(N)Space: O(1)

Initialize Hash Map

Target is 0. We iterate through nums array and maintain a hash map of { value: index }.

Array Elements & Pointers
1
i=0
2
i=1
3
i=2
Live Variables & Invariants
target:0
i:0
current:-
complement:-
Step 1 / 714%
Solution Code
1
function isAnagram(s: string, t: string): boolean {
2
  if (s.length !== t.length) return false;
3
  const count = new Array(26).fill(0);
4
  for (let i = 0; i < s.length; i++) {
5
    count[s.charCodeAt(i) - 97]++;
6
    count[t.charCodeAt(i) - 97]--;
7
  }
8
  return count.every(c => c === 0);
9
}

Custom Test Case Runner

Input your custom values and visualize step-by-step trace

Quick Presets:

AI DSA Coach

Contextual Tutor for Valid Anagram

Hello! I am your AI DSA Tutor for **Valid Anagram** (Arrays & Hashing). Ask me anything about this algorithm, time complexity, or request a step hint!