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.