Find total combinations of length 3 such that sum is divisible by a given number and i<j<k
The key here is to think about the modulus operator. Each number n in the list can be expressed as n = (x*d) + y, where y = n % d.
For any 3 integers x, y, z, (x + y + z) will be divisible by d if and only if (x%d + y%d + z%d) % d = 0.
You can bucket all numbers in the list based their remainder (ie. n%d)
You will have d buckets (ranging from 0 to d-1).
Generate all possible triplets using integers in range [0, d-1] that add up to 0, d or 2*d. This will give you the bucket combinations that can be used to obtain a valid triplet.
Since you know the number of elements in each bucket, you can calculate the number of valid triplets. (for example, if bucket 0 has 10 elements, the triplet (0,0,0) will have 10*9*8 corresponding triplets).

This algorithm should be enough to set you on track to complete the problem. Leaving out the implementation and other minor details for the reader.
So, I have been trying to find optimum solution for the question, but I can not find a solution which is less than o(n3).
The problem statemnt is :-
find total number of triplet in an array such that sum of a[i],a[j],a[k] is divisible by a given number d and i<j<k.
I have tried a multiple solutions but the solutions all reached o(n3). I need a solution that could be less than o(n3)