Skip to main content
All Visualizers
#LC 242•Arrays & Hashing•Easy

Valid Anagram

Decide whether the two strings contain the same characters with the same frequencies.

Understand the problem

Decide whether the two strings contain the same characters with the same frequencies.

Example 1

Input: {"s": "anagram", "t": "nagaram"}

Output: true

Follow the trace to see how the algorithm reaches this result.

Constraints

  • Use the input format shown in the example.
Think first

What information should you keep so you can solve the next step efficiently?

Pattern tags:Hash mapFrequency counting
Time: O(n)Space: O(1)
Step 1 of 5 • Use Left/Right arrows or Space to control