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

Detect if an array contains a Pythagorean triplet by checking if there are three integers x, y, and z such that x^2 + y^2 = z^2.

  • Iterate through all possible triplets of numbers in the array and check ...read more

Help your peers!
Select
Add answer anonymously...

Tata CLiQ Software Developer interview questions & answers

A Software Developer was asked Q. Reach the Destination Problem Statement You are given a source point (sx, sy) an...read more
A Software Developer was asked Q. Cycle Detection in a Singly Linked List Determine if a given singly linked list ...read more
A Software Developer was asked Q. Pythagorean Triplets Detection Determine if an array contains a Pythagorean trip...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Reach the Destination Problem Statement You are given a source point (sx, sy) an...read more
A Software Developer was asked Q2. Cycle Detection in a Singly Linked List Determine if a given singly linked list ...read more
A Software Developer was asked Q3. Pythagorean Triplets Detection Determine if an array contains a Pythagorean trip...read more
Tata CLiQ 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