You are viewing a single comment's thread. Return to all comments →
Hello, using the Editorial suggestion :
function countTriplets(arr, r) { let result = 0 const left = new Map(), right = new Map() arr.forEach((elem) => { const tmp = right.get(elem) || 0 right.set(elem, tmp+1) }) arr.forEach((elem) => { if (right.has(elem)) right.set(elem, right.get(elem) - 1) const c1 = right.get(elem * r) || 0 const c2 = left.get(elem / r) || 0 result += c1 * c2 left.set(elem, (left.get(elem) || 0) + 1) }) return result }
Count Triplets
You are viewing a single comment's thread. Return to all comments →
Hello, using the Editorial suggestion :