VOOZH about

URL: https://www.geeksforgeeks.org/dsa/construction-of-longest-monotonically-increasing-subsequence-n-log-n/

⇱ Construction of Longest Increasing Subsequence (N log N) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Construction of Longest Increasing Subsequence (N log N)

Last Updated : 23 Jul, 2025

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). 


Output
LIS of given input
13 10 8 7 3 2 
LIS size 6

Time Complexity: O(N*log(N))
Auxiliary Space: O(N)

Exercises:

  1.  You know Kadane's algorithm to find maximum sum sub-array. Modify Kadane's algorithm to trace starting and ending location of maximum sum sub-array.
  2.  Modify Kadane's algorithm to find maximum sum sub-array in a circular array. Refer GFG forum for many comments on the question.
  3.  Given two integers A and B as input. Find number of Fibonacci numbers existing in between these two numbers (including A and B). For example, A = 3 and B = 18, there are 4 Fibonacci numbers in between {3,  5, 8, 13}. Do it in O(log K) time, where K is max(A, B). What is your observation?
Comment
Article Tags:
Article Tags: