Pergunta de entrevista da empresa Amazon

Optimize a system for finding pairs of numeric values in a list which sum to a specified third value.

Respostas da entrevista

Sigiloso

17 de mar. de 2012

The previous answer seems to assume that all elements are positive. So, intead, create a search structure (by sorting or creating a hash table) and then for each element search for another element that is the difference between the sum and the the given element.

1

Sigiloso

27 de mai. de 2011

Sort and traverse the list in both directions (i >= 0, j < Count), trying to find list[i]+list[j]=Sum. End when j < i. O(n Log n) complexity.