You are viewing a single comment's thread. Return to all comments →
Same solution but in JS
function countTriplets(arr, r) { let mp2 = {}; let mp3 = {}; let count = 0; arr.forEach(val => { if(mp3.hasOwnProperty(val)) count += mp3[val]; if(mp2.hasOwnProperty(val)) mp3[val*r] = (mp3[val*r] += mp2[val]) || mp2[val]; mp2[val*r] = (mp2[val*r] += 1) || 1 ; }); return count; }
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 →
Same solution but in JS