You are viewing a single comment's thread. Return to all comments →
Nice... with Counter looks almost magic:
from collections import Counter def countTriplets(arr, r): result = 0 dictOne = Counter() dictPairs = Counter() for i in reversed(arr): result += dictPairs[i*r] dictPairs[i] += dictOne[i*r] dictOne[i] += 1 return result
Seems like cookies are disabled on this browser, please enable them to open this website
Count Triplets
You are viewing a single comment's thread. Return to all comments →
Nice... with Counter looks almost magic: