![]() |
VOOZH | about |
In my previous post, I have explained about longest increasing sub-sequence (LIS) problem in detail. However, the post only covered code related to querying size of LIS, but not the construction of LIS. I left it as an exercise. If you have solved, cheers. If not, you are not alone, here is code.
If you have not read my previous post, read here. Note that the below code prints LIS in reverse order. We can modify print order using a stack (explicit or system stack). I am leaving explanation as an exercise (easy).
LIS of given input 13 10 8 7 3 2 LIS size 6
Time Complexity: O(N*log(N))
Auxiliary Space: O(N)
Exercises: