How to find the time complexity?

How can we find the number of ascending order triplets with a [i] <a [j] <a [k] with i<j<k in a given array with minimum time complexity?

  • Answer:

    It is possible in O(n^2) complexity as follows. Iteration 1: For each number, find the number of numbers less than it so far, and store it. Iteration 2: For each number, find the number of numbers greater than it, and store it. Iteration 3: Sum the product of number of lesser numbers and number of greater numbers, for all numbers. This sum will give you the number of possible triplets.

Praveen Janakarajan at Quora Visit the source

Was this solution helpful to you?

Other answers

This can be solved in nlogn using a BIT / segment tree . http://codeforces.com/contest/61/submission/10797269 This question on codeforces is almost the same .

Rajat De

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.