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.
AnswerBot
4mo

Check if a Pythagorean triplet exists in a given array of integers.

  • Iterate through all possible combinations of three numbers in the array and check if they form a Pythagorean triplet.

  • Use a nested loo...read more

Help your peers!
Select
Add answer anonymously...

Amdocs Software Developer interview questions & answers

A Software Developer was asked 5mo agoQ. Explain joins in detail and provide a 100-line code example for review.
A Software Developer was asked 5mo agoQ. What is inheritance?
A Software Developer was asked 5mo agoQ. What are interfaces, and can you demonstrate their use with an example?

Popular interview questions of Software Developer

A Software Developer was asked 6mo agoQ1. What are the key concepts of Object-Oriented Programming (OOP)?
A Software Developer was asked 6mo agoQ2. What is the internal working mechanism of a HashMap?
A Software Developer was asked 8mo agoQ3. What is SDLC and what are its types?
Amdocs Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits