Given a sorted list \((a_0,...,a_{n-1})\) of \(n\) Integers. Find three different indices \(p\), \(q\), \(r\) such that \((a_p, a_q, a_r)\) (if they exist) the following condition holds: \(a_p + a_q + a_r = 0\). Warning: The sorted list can contain the same integer multiple times.
Design and implement a quadratic algorithm for this problem.
Write a function findZeroSumTriplet(gesorteerd: list)
. This function takes a sorted list as input argument and returns a tuple containing the indices. If no sum could be found you should return None
.
>>> findZeroSumTriplet([-5, 1, 2, 3, 7, 8])
(0, 2, 3)
>>> findZeroSumTriplet([ -16, -3, 2, 3, 5, 6, 7, 19])
(0, 1, 7)
>>> findZeroSumTriplet([-16, -3, 2, 3, 5, 6, 7])
>>> findZeroSumTriplet([-9, -8, -3, -1, 2, 5, 7, 13, 18])
(0, 4, 6)
>>> findZeroSumTriplet([-4, -4, -2, 3, 5, 8, 10])
(0, 1, 5)
>>> findZeroSumTriplet([-4, -4, 3, 5, 9, 10])
>>> findZeroSumTriplet([])