This is a
solution to
problem 29 on the
hard interview questions node. If you have not read the
question, the
following will make no
sense to you:
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.