Media.net interview question
Anonymous User
5360

Given a permutation of numbers from 1 to n, count the number of quadrapules indices (i,j,k,l) such that i<j<k<l and A[i]<A[k]<A[j]<A[l].

I was not able to improve on the time complexity compared to the brute force solution. How to solve this? Can some precomputation be used? It would also be great if someone can suggest similar problems for practice.

Example:
[1,3,2,6,5,4]
first 4 indices satisfy the given condition.

Comments (8)