← Discussions on Isomorphic Strings
R riyachatterjee OFFICIAL
10 Oct 2026, 15:29

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.

2 replies

dkaur 1 week ago

You can avoid the extra array and do it in O(1) space.

iagarwal 1 week ago

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

Sign in to reply.