Longest Common Increasing Subsequence
InterviewTime limit1sMemory limit128 MB
Find the length of the longest strictly increasing sequence that is a subsequence of both given sequences.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
You are given two sequences of positive integers, and . A common increasing subsequence is a sequence that appears as a subsequence of both and and is strictly increasing, meaning every element is greater than the one before it. (The elements of a subsequence need not be adjacent in the original sequence.) Find the length of the longest common increasing subsequence of and .
Input
The first line contains two integers and (), the lengths of and . The second line contains the elements of , and the third line contains the elements of , separated by single spaces. Every element is a positive integer not exceeding .
Output
Print a single integer: the length of the longest common increasing subsequence of and . If and share no common element, print .