Pythagorean Triples

Given an integer array, find all Pythagorean triples.

Statement

Given an integer array, find all Pythagorean triples (a2a^2 + b2b^2 = c2c^2), where aa, bb and cc are the array elements.

Example

Here is a sample array.

g array 4 16 1 2 3 5 6 8 25 10

Sample input

[4, 16, 1, 2, 3, 5, 6, 8, 25, 10]

Expected output

[[3, 4, 5], [6, 8, 10]]

The triples are calculated as:

323^2 + 424^2 = 525^2 and 626^2 + 828^2
...
Access this course and 1400+ top-rated courses and projects.