Valid Anagram
Character Frequency Count — Fixed-Size Array
LeetCode 242 • Easy • Arrays & Hashing
Input: s = "anagram", t = "nagaram" → Output: true (same letters, rearranged)
TimeO(n)single pass
SpaceO(1)fixed 26 slots
Processed: 0/7
Non-zero: 0
Verified: 0/26
Current s[i]
Current t[i]
Count updated
Balanced (0)
Imbalanced
Index
—
Count[s[i]]
—
Count[t[i]]
—
Result
—
Ready
Press Play to watch the algorithm, or Step to advance one operation at a time.
For each index i, increment count[s[i]] and decrement count[t[i]]. If all counts end at zero, it's an anagram.
For each index i, increment count[s[i]] and decrement count[t[i]]. If all counts end at zero, it's an anagram.