educative.io

Educative

Cannot find all Pythagorean Triplets with solution2

for Solution2:

Original: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
Pythagorean triplets: [3, 4, 5],[6, 8, 10],[5, 12, 13],[9, 12, 15],[8, 15, 17],[12, 16, 20],[7, 24, 25]

Problem in code:
if a2 + b2 == c2:
triplets.append([arr[j], arr[k], arr[i]])
break

after we find [7, 24, 25], the loop break, so we will never find [15, 20, 25]

But the actual output should be:
[3, 4, 5],[6, 8, 10],[5, 12, 13],[9, 12, 15],[8, 15, 17],[12, 16, 20],[7, 24, 25], [15, 20, 25]

Yes you are correct, solution 2 does not show all the triplets.