← Discussions on Ransom Note
K kavyasub5 OFFICIAL
12 Jul 2026, 10:19

Clean Python 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

rohit_74 2 months, 4 weeks ago

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

Sign in to reply.