Common Subsequence
Easy Accuracy: 42.22% Submissions: 135 Points: 2

Given two strings a and b. Check whether they contain any common subsequence (non empty) or not.

Example 1:

a = "ABEF" b = "CADE"
Output: 1
Explanation: Subsequence "AE" occurs
in both the strings.

​Example 2:

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).

2 <= |a|, |b| <=105


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.

Output Window