Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Algorithms/triplet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
A simple Python 3 program
to find three elements whose
sum is equal to zero

Prints all triplets in
arr[] with 0 sum

"""

def findTriplets(arr, n):

found = True
for i in range(0, n-2):

for j in range(i+1, n-1):

for k in range(j+1, n):

if (arr[i] + arr[j] + arr[k] == 0):
print(arr[i], arr[j], arr[k])
found = True


# If no triplet with 0 sum
# found in array
if (found == False):
print(" not exist ")


arr = [0, -1, 2, -3, 1]
n = len(arr)
findTriplets(arr, n)