Pythagorean Triplet Problem
Determine if there exists a Pythagorean triplet within a given array of integers. A Pythagorean triplet consists of three numbers, x, y, and z, such that x^2 + y^2 = z^2.
Explanation:
You are provided with an array of n integers. You need to check if there are numbers x, y, z in this array that satisfy the condition x^2 + y^2 = z^2.
Input:
The first line contains a single integer t
- the number of test cases.
Each test case consists of two lines:
- First line: An integer n
, the size of the array.
- Second line: n
space-separated integers representing the elements of the array.
Output:
For each test case, output "yes" if a Pythagorean triplet exists in the array, otherwise "no".
Example:
Input:
t = 2
n = 5
array = [3, 1, 4, 6, 5]
Output:
"yes"
Explanation: 3^2 + 4^2 = 5^2
Constraints:
- 1 <= T <= 10
- 3 <= N <= 10^3
- 1 <= a[i] <= 10^4
Note:
Do not print anything; implement the function only. Indices i, j, and k for x, y, and z respectively must be distinct.
Be the first one to answer
Add answer anonymously...
Top Amdocs Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Amdocs Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app