← Discussions on Valid Anagram
K kavyanaidu
06 Aug 2026, 17:09

Finally got AC after 3 WAs. Sharing what I missed.

Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.

1 reply

kunalagarwal 2 months ago

This should be marked as the editorial approach honestly.

Sign in to reply.