← Discussions on Valid Anagram
K kavyanaidu OFFICIAL
18 Jul 2026, 14:40

Why does my solution TLE on the last test case?

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.

3 replies

gurpreet_92 2 months, 4 weeks ago

This should be marked as the editorial approach honestly.

aniketpil6 2 months, 3 weeks ago

Watch out for integer overflow in Java on the large test.

sreddy 2 months, 3 weeks ago

This should be marked as the editorial approach honestly.

Sign in to reply.