AI Exploration Journey

AI Exploration Journey

Share this post

AI Exploration Journey
AI Exploration Journey
Longest Common Subsequence(LCS) of Two Permutations

Longest Common Subsequence(LCS) of Two Permutations

By a clever transformation, the classic LCS problem is converted to an LIS problem, thereby reducing the time complexity.

Florian's avatar
Florian
Jun 18, 2023
∙ Paid

Share this post

AI Exploration Journey
AI Exploration Journey
Longest Common Subsequence(LCS) of Two Permutations
Share

Given two permutations P1 and P2 of 1, 2, …, n, find their longest common subsequence(LCS), n <= 10⁵.

For example, input: The first line contains an integer n. The next two lines each contain a permutation of n natural numbers from 1 to n.

5 
3 2 1 4 5
1 2 3 4 5

So you need to output:

3

Because the length of the LCS (1, 4, 5 or 3, 4, 5or 2, 4, 5 )of these two permutations is 3.

The question is from Codeforces: https://codeforces.com/gym/102951/problem/C

Keep reading with a 7-day free trial

Subscribe to AI Exploration Journey to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Florian June
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share