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.
I solved this using two hashmaps/dictionaries.
The idea is to iterate using the middle element (let's call it i) of the triplet, and maintaining two hashmaps/dictionaries, one which holds all the elements before i, and the other holds all the elements after i. At the beginning of each iteration, remove i from the after hashmap, and at the end of each iteration, add i to the before hashmap.
Count Triplets
You are viewing a single comment's thread. Return to all comments →
I solved this using two hashmaps/dictionaries. The idea is to iterate using the middle element (let's call it i) of the triplet, and maintaining two hashmaps/dictionaries, one which holds all the elements before i, and the other holds all the elements after i. At the beginning of each iteration, remove i from the after hashmap, and at the end of each iteration, add i to the before hashmap.
Here is the solution implemented in python: