← Discussions on First Unique Character
J jahnavisub6
14 Sep 2026, 16:07

Asked in my Salesforce OA last week.

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

inaidu 1 month ago

Same idea, but I used a deque. Works fine.

meeradas1 1 month ago

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

vamsisax3 1 month ago

Thanks! The dry run on the second example made it click.

Sign in to reply.