1163. Shortest Common Supersequence Length

EasyDynamic ProgrammingSequence DPLCS

Given two strings a and b, return the length of the shortest string that has both a and b as subsequences. The input is JSON {a, b}.

Input: JSON {a, b}.

Output: Integer — the length of the shortest common supersequence.

Examples

Example 1
Input: {"a":"abac","b":"cab"}
Output: 5
Explanation: Length 5 covers both.
Example 2
Input: {"a":"abc","b":"abc"}
Output: 3
Explanation: Identical strings.
Example 3
Input: {"a":"a","b":""}
Output: 1
Explanation: Just a.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →