Pergunta de entrevista da empresa Yahoo

Find two numbers in an array that sum up to 0.

Resposta da entrevista

Sigiloso

20 de abr. de 2014

Take each number (num) and do it {res = 0-num} . Look for result (res) using binary search. So for e.g if my array is {5,6,-5,8} take num =5, compute res = 0 - num = -5, look for -5 using binary search in log n time, if you get it output {5, -5}. For n number it will take O(nlogn) time.