Answer to Question #197013 in Python for Hari nadh babu

Question #197013

Triplet Sum


Write a Python Program for Triplet Sum


The below link contains Triplet Sum Question and test cases


https://drive.google.com/file/d/1kPR1eOaf9JTOqqAj4w_A4e8Nc0jIa3fM/view?usp=sharing


1
Expert's answer
2021-05-24T10:15:03-0400
integers = [int(number) for number in input().split()]
integers.sort()
K = int(input())


triplets = []


for i in range(len(integers)):
    for j in range(len(integers)):
        for k in range(len(integers)):
            a = integers[i]
            b = integers[j]
            c = integers[k]


            if a+b+c == K:
                triplet = [a,b,c]
                triplet.sort()
                
                triplet = tuple(triplet)
                if triplet not in triplets:
                    triplets.append(triplet)


if len(triplets) == 0:
    print("No Matching Triplets Found!")
else:
    for triplet in triplets:
        print(triplet)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS