Another longest inc subseq


the n*n method gives tle in this que ,how to implement binary search lis method on pairs ??

Hey @Ashu1318 take this for reference

actually cant understood the logic of this solution ,can explain it little bit more

A pair (a,b) is less than another pair (c,d) if and only if a < c and b < d.

This can be easily solved in O(N^2) time by adapting the standard dynamic programming technique.
The classic O(N log N) solution to the standard LIS problem can be extended to give a subquadratic solution to the LIS problem with pairs, with some difficulty. We cannot simply remember one minimum value for every possible length; we have to maintain “staircase-like” structures containing all minimal pairs for each length, that is, up to N copies of the data structure described here, implemented using an ordered dynamic set of pairs keyed on the first member. We can then query one copy of this structure in O(log N) time (to check whether it contains any pair less than the current pair), giving O(log^2 N) time for the binary search step, and O(N log^2 N) time in all. This is the fastest solution I know to the problem.

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.