Skip to content

Commit

Permalink
Update beautifulTriplet.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansumanbhujabal committed Feb 28, 2024
1 parent 27b21c6 commit 3c2a97b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Python_Problems/beautifulTriplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ def beautifulTriplets(d, arr):
return len(total)//3


# Optimized

def beautifulTriplets(d, arr):
total = sum(1 for i in arr if i+d in arr and i+2 *
d in arr) # counts 1 for each element
return total


print(beautifulTriplets(1, [2, 2, 3, 4, 5]))

0 comments on commit 3c2a97b

Please sign in to comment.