1160. Longest Common Subsequence — Basic

EasyDynamic ProgrammingSequence DPLCS

Given two strings a and b, return the length of their longest common subsequence — the longest sequence of characters appearing in both in the same relative order (not necessarily contiguous). The input is JSON {a, b}.

Input: JSON {a, b}.

Output: Integer — the length of the longest common subsequence.

Examples

Example 1
Input: {"a":"abcde","b":"ace"}
Output: 3
Explanation: 'ace' is common.
Example 2
Input: {"a":"abc","b":"def"}
Output: 0
Explanation: No common characters.
Example 3
Input: {"a":"","b":"a"}
Output: 0
Explanation: Empty string.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →