problem statement
my code
problem statement
my code
Hello @Namanjain123
Your code is correct but has a time complexity of O(N^2) whereas you need a time complexity of O(Nlog(N)) in order to solve this problem.
Think of an efficient way to calculate these pairs.
Read the below hint only if you are NOT able to come up with another efficient approach.
HINT to begin with. Find maximum value and sort sub-arrays in the left and in the right. Count efficiently (sub-arrays are sorted) how many pairs fulfill the condition. Repeat recursively this operation in right and left sub-arrays.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.