1162. Print Longest Common Subsequence

EasyDynamic ProgrammingSequence DPLCS

Given two strings a and b, return one longest common subsequence as a string. When multiple exist, return the one obtained by preferring to move up (decrease the index into a) on ties during reconstruction. The input is JSON {a, b}.

Input: JSON {a, b}.

Output: String — a longest common subsequence.

Examples

Example 1
Input: {"a":"abcde","b":"ace"}
Output: ace
Explanation: The LCS is 'ace'.
Example 2
Input: {"a":"abc","b":"abc"}
Output: abc
Explanation: Whole string.
Example 3
Input: {"a":"a","b":"b"}
Output: 
Explanation: Empty LCS.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →