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.
By second part of the triplet I'm referring to the B part.
In this thread at least there's no java version, just my C++, a couple of Python and a C# (also mine). I haven't checked the whole forum for a Java version.
I use the current value x to check if it's a possible C to a (possibly multiple) set of A's and B's already seen. If so I accumulate these new triplets.
I the use the current value x to check if it's a possible B to previously seen A's. If so I add this to possible future C's which might need this B to complete triplets.
Finally whatever the value of x is it's always a possible A of a triplet so I ensure that future B's will find it.
Count Triplets
You are viewing a single comment's thread. Return to all comments →
By second part of the triplet I'm referring to the B part.
In this thread at least there's no java version, just my C++, a couple of Python and a C# (also mine). I haven't checked the whole forum for a Java version.
Maybe check https://www.hackerrank.com/challenges/count-triplets-1/forum/comments/474943 (4th post for this thread) for a detailed explanation. This doesn't actually mean all implementations follow this. Some of the other solutions process the array in reverse and are equally valid.
I use the current value x to check if it's a possible C to a (possibly multiple) set of A's and B's already seen. If so I accumulate these new triplets.
I the use the current value x to check if it's a possible B to previously seen A's. If so I add this to possible future C's which might need this B to complete triplets.
Finally whatever the value of x is it's always a possible A of a triplet so I ensure that future B's will find it.