← Discussions on First Unique Character
K kgoud OFFICIAL
04 Oct 2026, 03:49

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.

1 reply

ravimalhotra 1 week, 4 days ago

Great explanation, the edge case with an empty input tripped me up too.

Sign in to reply.