This is a solution
29 on the hard interview questions node
. If you have not read the question
, the follow
ing will make no sense
First, square each element of the array. Then insert every pair of elements in the array into a hash table, using their sum as the hash code. This step is O(n2). Now, we can easily (O(n) time) test if any element in the array is the sum of a pair of elements by looking up that element in the hash table. These three elements form a Pythagorean triple.