Count Triplets

  • + 0 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.

    1. If so, increment the count variable, else directly proceed step-2.
    2. Also check whether (num * r) may form triplet. If so, increment the mp3[num * r], else directly proceed step-3.
    3. Finally, increment the mp2[num * r] because (num * r) may form doublet in future.

    I hope this is helpful!