You are viewing a single comment's thread. Return to all comments →
Based on the editorial notes in C++
long countTriplets(vector<long> arr, long r) { unordered_map<long, long> left, right; long occurences = 0; for(auto const item : arr) { right[item]++; } for(auto const item : arr) { right[item]--; if (right.count(item * r) && (item % r == 0) && left.count(item / r)) { occurences += right[item * r] * left[item / r]; } left[item]++; } return occurences; }
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 →
Based on the editorial notes in C++