Sollicitatievragen voor enterprise account executive gedeeld door sollicitanten
check if there is a set of 3 elements in an integer array, that adds upto zero?
Sort it, hold references to start and end, move down if the sum is less than zero, move up if the sum is less and do the binary search in the array if there is a third element in the array which can produce zero if added to the sum.
Similar to the answer above but without the binary search. Still a quadratic answer, but better than the naive qubic answer. def three_set_sum(seq): n = len(seq) if n j: sum = seq[i] + seq[j] + seq[k] if sum == 0: return True if sum > 0: k-=1 else: j+=1 return False