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.
Another approach that resembles the popular one here. It enumerates the array backward and builds an imaginable graph of connections a --> a*r --> a*r*r. But instead of building an actual graph it just accumulates statistics of nodes connections. That approach takes O(N), too, but utilizes a single map only! R = 1 is processed in a general way, too.
C++14 code is down below:
Count Triplets
You are viewing a single comment's thread. Return to all comments →
Another approach that resembles the popular one here. It enumerates the array backward and builds an imaginable graph of connections a --> a*r --> a*r*r. But instead of building an actual graph it just accumulates statistics of nodes connections. That approach takes O(N), too, but utilizes a single map only! R = 1 is processed in a general way, too. C++14 code is down below: