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.
Hi, this is very simple & very optimised approach.
Consider mp3 have a count of numbers which may form triplet if the (num * r) is identified once again.
Similarly, mp2 have a count of numbers which may form doublet if the (num * r) is identified once again.
Follow the below 3 steps for every num encountered.
So, First, we need to check whether the number num is in mp3, (i.e) num formed triplet or not.
If so, increment the count variable, else directly proceed step-2.
Also check whether (num * r) may form triplet. If so, increment the mp3[num * r], else directly proceed step-3.
Finally, increment the mp2[num * r] because (num * r) may form doublet in future.
I hope this is helpful!
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 →
Hi, this is very simple & very optimised approach. Consider mp3 have a count of numbers which may form triplet if the (num * r) is identified once again.
Similarly, mp2 have a count of numbers which may form doublet if the (num * r) is identified once again.
Follow the below 3 steps for every num encountered. So, First, we need to check whether the number num is in mp3, (i.e) num formed triplet or not.
I hope this is helpful!