You are viewing a single comment's thread. Return to all comments →
my solution
function countTriplets(arr, r) { let totalCount = 0 const possibilities = {} const combos = {} arr.forEach((number) => { totalCount += (combos[number] || 0); const nextNumber = number * r; combos[nextNumber] = (combos[nextNumber] || 0) + (possibilities[number] || 0) possibilities[nextNumber] = (possibilities[nextNumber] || 0) + 1 }) return totalCount }
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 →
my solution