Pythagorean Triplets Detection
Determine if an array contains a Pythagorean triplet by checking whether there are three integers x, y, and z such that x2 + y2 = z2 within the array.
Input:
The first line contains an integer 't', the number of test cases. Each test case has the following format: For each test case, the first line has an integer 'n', the number of elements in the array. The second line lists 'n' space-separated integers.
Output:
For each test case, output “yes” if a Pythagorean triplet is present, otherwise output “no”.
Example:
If the input is as follows:
t = 1, n = 5, array = [3, 1, 4, 6, 5]
The output would be:
yes
Constraints:
1 <= T <= 10
3 <= N <= 103
1 <= a[i] <= 104
- Time Limit: 1 second
Note:
- The integers x, y, and z do not need to be distinct but must be from different indices.
- The integers can appear in any order in the array.
AnswerBot
7d
Detect if an array contains a Pythagorean triplet by checking if x^2 + y^2 = z^2.
Iterate through all possible combinations of three numbers in the array.
Check if the sum of squares of any two numbers ...read more
Help your peers!
Add answer anonymously...
Top Amdocs Associate Software Engineer interview questions & answers
Popular interview questions of Associate Software Engineer
Top HR questions asked in Amdocs Associate Software Engineer
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