Approach Summary
Store all pairwise sums of A+B in a HashMap. Count how many C+D values equal the negation of a stored sum.
How to Recognize This Pattern
- Four arrays, each of length n — O(n²) must beat O(n⁴)
- Meet-in-the-middle: A+B sums vs -(C+D) sums
Complexity Analysis
Time Complexity
O(n²)
Space Complexity
O(n²)
Tags
Array Hash Table