← Discussions on Roman to Integer
D dkaur
02 Jul 2026, 18:59

Finally got AC after 3 WAs. Sharing what I missed.

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

kavyanai4 3 months, 1 week ago

For the TLE: you are rebuilding the list inside the loop, move it outside.

Sign in to reply.