Diferente pentru blog/meet-in-the-middle intre reviziile #84 si #83
Nu exista diferente intre titluri.
Diferente intre continut:
A slightly improved algorithm brute forces through all $n^3^$ three number combinations and efficiently checks if -(a + b + c) is in the original array using a hash table. This algorithm has $O(n^3^)$ complexity.
By now, you’re probably wondering how the meet in the middle technique canbe applied here. Thecritical insight comes from rewriting $a + b + c + d = 0$ as $a + b = -(c + d)$.
By now, you’ve probably started wondering how the meet in the middle technique could be applied here. The insight comes from rewriting $a + b + c + d = 0$ as $a + b = -(c + d)$.
Now we store all $n^2^$ sums $a + b$ in a hash set $S$. Then iterate through all $n^2^$ combinations for c and d and check if $S$ contains -(c + d). Here's how the code looks
