Pythagorean Triplet Detection
Determine whether an array contains a Pythagorean triplet. A Pythagorean triplet exists if there are three integers x, y, z such that x2 + y2 = z2 within the array.
Input:
The first line of input contains an integer t, representing the number of test cases.
Each test case consists of two lines:
The first line contains an integer n, which is the number of elements in the array.
The second line contains n space-separated integers a1, a2, ..., an.
Output:
For each test case, output "yes" if a Pythagorean triplet exists, otherwise "no".
Example:
Input:
2
5
3 1 4 6 5
3
1 2 3
Output:
yes
no
Explanation:
In the first test case, the numbers 3, 4, and 5 form a Pythagorean triplet (32 + 42 = 52). In the second test case, no such triplet exists.
Constraints:
1 <= T <= 10
3 <= N <= 103
1 <= a[i] <= 104
- Time Limit: 1 second
Note:
The integers x, y, and z might not be distinct but should be at different locations in the array.

AnswerBot
4mo
Detect if an array contains a Pythagorean triplet.
Iterate through all possible triplets in the array and check if they form a Pythagorean triplet.
Use a nested loop to generate all possible combination...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ. What is MySQL?
A Software Developer was asked 1mo agoQ. What is Java?
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 1mo agoQ3. What is Java?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

