Copied to Clipboard
Print all LCS sequences
Hard Accuracy: 63.69% Submissions: 3702 Points: 8

You are given two strings s and t. Now your task is to print all longest common sub-sequences in lexicographical order.

Example 1:

Input: s = abaaa, t = baabaca
Output: aaaa abaa baaa

Example 2:

Input: s = aaa, t = a
Output: a

Your Task:
You do not need to read or print anything. Your task is to complete the function all_longest_common_subsequences() which takes string a and b as first and second parameter respectively and returns a list of strings which contains all possible longest common subsequences in lexicographical order.


Expected Time Complexity: O(n4)
Expected Space Complexity: O(K * n) where K is a constant less than n.


1 ≤ Length of both strings ≤ 50

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Print all LCS sequences

Output Window