Using hashing to solve 4-sum problem
Suppose $A[i] + A[j] + A[k] + A[\ell] = X$. If there is a way to break this sum into two non-equal parts, then the problem you mention does not occur. Otherwise, we have
\begin{align}
A[i] + A[j] &amp;= A[k] + A[\ell] \\
A[i] + A[k] &amp;= A[j] + A[\ell] \\
A[i] + A[\ell] &amp;= A[j] + A[k]
\end{align}
In fact, all of these are equal to $X/2$, and this implies that $A[i] = A[j] = A[k] = A[\ell]$.
The hashtable entry for $X/2$ can only contain two of the indices $i,j,k,\ell$, say $i,j$ (it might contain fewer). The algorithm then finds the correct solution when it reaches $k,\ell$ in the second stage.