Pergunta de entrevista da empresa Meta

In the last interview: Given a array, do a function that returns true if there are two elements whose sum is 0. Then he asked me to check if there are three element whose sum is 0.

Resposta da entrevista

Sigiloso

20 de jun. de 2015

The worst way is O(n^2), but you could sort and check in O(nlogn) and also create a map and for each A[val] check in the map if the element -A[val] exists, O(n) complexity. I failed to extend it to three elements, but it's pretty simple (just do it N times, checking for -A[val]-A[i]).