We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Most people agree that even though division is the intuitive way to solve this, it is better to use multiplication. So, as opposed to looking back in the map to see that you have already processed the two previous triplets, at each step you calculate if you are one of the "next" triplets
1) If you are the third triplet you increment the count in how many times you are expected (the value in the map for 'k'
2) If you are expected as 'j' (second triplet), calculate the expected k and add 1 to the map of expected k
3) Whatever value you are, add yourself times r as the expected 'j'
Count Triplets
You are viewing a single comment's thread. Return to all comments →
Hi,
Most people agree that even though division is the intuitive way to solve this, it is better to use multiplication. So, as opposed to looking back in the map to see that you have already processed the two previous triplets, at each step you calculate if you are one of the "next" triplets 1) If you are the third triplet you increment the count in how many times you are expected (the value in the map for 'k' 2) If you are expected as 'j' (second triplet), calculate the expected k and add 1 to the map of expected k 3) Whatever value you are, add yourself times r as the expected 'j'
Your code is not wrong, but perhaps the long division is not working as you expect it for one single value in the 100000 values for case 6.
Hope this helps!