![]() |
VOOZH | about |
Given a sequence of numbers in the form of a linked list lis. Find the length of the Longest Increasing Subsequence(LIS) of the given Linked List.
Examples:
Input: list = 3->10->2->1->20
Output: 3
Explanation: The longest increasing subsequence is 3->10-> 20Input: list = 3-> 2
Output: 1
Explanation: The longest increasing subsequence are 3 and 2Input: list = 50->3->10->7->40->80
Output: Length of LIS = 4
Explanation: The longest increasing subsequence is {3->7->40->80} or {3->10->40->80}
Approach: The basic intuition of the solution is to start iterating from the first node to the end of linked list .In the process of moving calculate length of LIS ending at every node and store it in a count variable. Finally, calculate maximum count value among all nodes. Follow the steps mentioned below to solve the problem:
Below is the implementation of the above approach:
3
Time Complexity: O(N * N) where N is the length of the linked list
Auxiliary Space: O(N)