You are viewing a single comment's thread. Return to all comments →
This one was a doozy! Took me way longer then I'd care to admit. JS solution (forgive my nesting 😅):
function countTriplets(arr, r) { let result = 0; const values = {}; const pairs = {}; for(const v of arr) { const prev = v/r; if(prev in values) { if (prev in pairs) result += pairs[prev]; pairs[v] = (pairs[v] ?? 0) + values[prev]; } values[v] = (values[v] ?? 0) + 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 →
This one was a doozy! Took me way longer then I'd care to admit. JS solution (forgive my nesting 😅):