Given 4 distinct numbers check if there is exist a sub-set of numbers with sum equals zero.
4 is small enough for us to just consider all possible sub-sets. I think most of the contestant will choose bitmask to implement the solution. Each sub-set can be represented by a 4-bit number where each bit 1 corresponding to a number that is chosen. You can refer to the pseudo code below:
result = "No" for s 1 -> 15: sum = 0; for i 0 -> 3 if bit ith of s is 1 then sum += a[i] if sum = 0: result = "Yes"; break;