Count Triplets
Problem
https://www.hackerrank.com/challenges/count-triplets-1/problem
Solution
Brute Force
Method: Brute force
Language: Python
Time complexity: O((Length of Array)3)
Space complexity: Constant
Test cases: 5/12 passed
Errors: Timeout reached
# Function fingerprint
def countTriplets(arr, r):
count = 0
n = len(arr)
for i in range(n):
for j in range(i+1, n):
if r == arr[j] / arr[i]:
count += arr[j+1:].count(arr[j]*r)
return count