Skip to content

Update 003. Count Triplets.py#1

Open
kartikshastrakar wants to merge 1 commit intoFreeBirdsCrew:masterfrom
kartikshastrakar:master
Open

Update 003. Count Triplets.py#1
kartikshastrakar wants to merge 1 commit intoFreeBirdsCrew:masterfrom
kartikshastrakar:master

Conversation

@kartikshastrakar
Copy link

add refactored method

add refactored method
@kartikshastrakar
Copy link
Author

from collections import defaultdict

def count_triplets(n, r, arr):
arr2 = defaultdict(int)
arr3 = defaultdict(int)
count = 0
for i in arr:
count += arr3[i]
arr3[i * r] += arr2[i]
arr2[i * r] += 1
return count

Example usage

n, r = map(int, input("Enter n and r: ").split())
arr = list(map(int, input("Enter array elements: ").split()))
result = count_triplets(n, r, arr)
print("Number of triplets:", result)

@kartikshastrakar
Copy link
Author

add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant