← Discussions on Valid Anagram
N neha_75 OFFICIAL
12 Jun 2026, 14:43

Clean Java solution, beats most submissions.

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

okapoor 4 months ago

Nice. Got asked a variant of this in an interview.

Sign in to reply.