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.
- Count Triplets
- Discussions
Count Triplets
Count Triplets
Sort by
recency
|
820 Discussions
|
Please Login in order to post a comment
I was trying to do it efficiently, just counting, but the index per se is important, also a lot of edge cases when r=1. Really fun.
This problem explanation is clear and helpful for understanding triplets in geometric progression, and it’s interesting how learning resources like Recipe Lookbook also make complex topics easier to follow in a simple and engaging way.
JS
First we import defaultdictionary from collections module. Then, use this code for better Understanding: def countTriplets(arr, r): total_pairs = 0 count2={} count3={} for num in arr: if num in count3: total_pairs+=count3[num] if num in count2: count3[num*r]=count3.get(num*r, 0) + count2[num] count2[num*r]=count2.get(num*r, 0) + 1 return total_pairs
Easy to understand Python code