From f535e979e2822f5243dd95185741d7d257a10d2b Mon Sep 17 00:00:00 2001 From: deepanshu malviya <41746116+mDeepanshu@users.noreply.github.com> Date: Sat, 2 Oct 2021 15:38:45 +0530 Subject: [PATCH 1/2] Added Solution for count triplets - python --- DSA/Python/Hashing/Count Triplets/Solution | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 DSA/Python/Hashing/Count Triplets/Solution diff --git a/DSA/Python/Hashing/Count Triplets/Solution b/DSA/Python/Hashing/Count Triplets/Solution new file mode 100644 index 0000000..be689a1 --- /dev/null +++ b/DSA/Python/Hashing/Count Triplets/Solution @@ -0,0 +1,18 @@ +from collections import Counter + +def countTriplets(arr, r): + a = Counter(arr) + b = Counter() + s = 0 + for i in arr: + j = i//r + k = i*r + a[i]-=1 + if b[j] and a[k] and i%r == 0: + s+=b[j]*a[k] + b[i]+=1 + return s + +n,r = map(int,input().split()) +arr = list(map(int,input().split())) +print(countTriplets(arr, r)) From cc7e5f4393bed8074181669f0414f49d8025d0c2 Mon Sep 17 00:00:00 2001 From: deepanshu malviya <41746116+mDeepanshu@users.noreply.github.com> Date: Sat, 2 Oct 2021 15:43:49 +0530 Subject: [PATCH 2/2] Added problem statement for count triplets in. --- .../Hashing/Count Triplets/Problem Statement | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 DSA/Python/Hashing/Count Triplets/Problem Statement diff --git a/DSA/Python/Hashing/Count Triplets/Problem Statement b/DSA/Python/Hashing/Count Triplets/Problem Statement new file mode 100644 index 0000000..609d2d3 --- /dev/null +++ b/DSA/Python/Hashing/Count Triplets/Problem Statement @@ -0,0 +1,17 @@ +You are given an array and you need to find number of tripets of indices (i,j,k) such that the elements at those indices are in geometric progression for a given common ratio r and i