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.
You'll come up against the problem of r=1 where you won't get the right answer. That's why my solution (at top) uses 2 maps rather than just one.
Also it can be done with a single loop which simplifies the need of the count-1 you're doing near the end.
The main issue I find is that the first loop can populate your map(s) with values which should not be available in the second pass (since they are "further down" the array).
Remember that the order in which values are given is important.
Cookie support is required to access HackerRank
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 →
You'll come up against the problem of r=1 where you won't get the right answer. That's why my solution (at top) uses 2 maps rather than just one. Also it can be done with a single loop which simplifies the need of the count-1 you're doing near the end.
The main issue I find is that the first loop can populate your map(s) with values which should not be available in the second pass (since they are "further down" the array).
Remember that the order in which values are given is important.