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
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
Related Q & A:
- How can I find the minimum number of open rectangles in a grid?Best solution by Stack Overflow
- How can I find the address with just a phone number?Best solution by Yahoo! Answers
- How can I find address from vehicle number?Best solution by Yahoo! Answers
- How can I find out what is on this small recorded tape I have?Best solution by Yahoo! Answers
- How can I find an online job that does not require a credit card?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.