P16275 [GeeksforGeeks] Common subsequence4049
普及-
题目描述

Given two strings a and b. Check whether they contain any common subsequence (non empty) or not.
Example 1:
Input:
a = "ABEF" b = "CADE"
Output: 1
Explanation: Subsequence "AE" occurs
in both the strings.
​Example 2:
Input:
a = "ABCD", b = "EFGH"
Output: 0
Explanation: There's no common subsequence
in both the strings.
Your Task:
You don't need to read input or print anything. Your task is to complete the function commonSubseq() which takes the string a and string b as inputs and returns true if there's a common subsequence in both the strings. Else, it returns false.
Expected Time Complexity: O(|a| + |b|).
Expected Auxiliary Space: O(1).
Constraints:
2 <= |a|, |b| <=10^{5}

输入格式

见题面

输出格式

见题面

样例输入
a = "ABEF" b = "CADE"
样例输出
1