So I have an array sized N. It is sure that array has all distinct elements.
I need to find sum of all possible triplets in that array and for that i need to find all possible triplets.
What i did: looping through array with three nested $for$ loops but that gives O(n^3).
I want to optimise the algorithm as n is very large(upto 10000)
Eg: Array==> {1,2,3,4,5}
Possible triplets: {1,2,3} {1,2,4} {1,2,5} {1,3,4} {1,3,5} {1,4,5} {2,3,4} {2,3,5} {2,4,5} {3,4,5}