-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpythagorian_triplet.py
47 lines (35 loc) · 1.12 KB
/
pythagorian_triplet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Pythagorean Triplet
# Submissions: 13057 Accuracy: 33.36% Difficulty: Easy
# Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a2 + b2 = c2.
# Input:
# The first line contains 'T' denoting the number of testcases. Then follows description of testcases.
# Each case begins with a single positive integer N denoting the size of array.
# The second line contains the N space separated positive integers denoting the elements of array A.
# Output:
# For each testcase, print "Yes" or "No" whtether it is Pythagorean Triplet or not.
# Constraints:
# 1<=T<=50
# 1<=N<=100
# 1<=A[i]<=100
# Example:
# Input:
# 1
# 5
# 3 2 4 6 5
# Output:
# Yes
def trapping_rain_water(arr,n):
for i in range(0,n):
arr[i] = arr[i]*arr[i]
arr = sorted(arr)
for i in range(0,n):
for j in range(i+1,n):
if arr[i]+arr[j] in arr:
print("Yes")
return
print("No")
t = int(input())
for i in range(0,t):
n = int(input())
arr = [int(x) for x in input().strip().split(" ")]
trapping_rain_water(arr,n)