Question d’entretien chez 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.

Réponse à la question d'entretien

Utilisateur anonyme

20 juin 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]).