Remove the Substring

Given 2 strings of lowercase alphabets A and B of size N and M respectively.

it is guaranteed that B is a subsequence of A.

For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".

You need to remove some substring(contiguous subsequence) from A of maximum possible length such that after removing this substring B will remain a subsequence of A.

If you want to remove the substring A[l::r] then the string A will be transformed to **A1A2…Al−1Ar+1Ar+2…A A −1A A ** (where ** A ** is the length of A).

Find and return the maximum possible length of the substring you can remove so that B is still a subsequence of A.



Input Format

The first argument given is the string A.
The second argument given is the string B.

Output Format

Return the maximum possible length of the substring you can remove so that B is still a subsequence of A.

Constraints

1 <= N, M <= 10^5

For Example

Input 1:
    A = "bbaba"
    B = "bb"
Output 1:
    3
Explaination 1:
    A[2::4] = "aba" can be removed and B still remains the subsequence of A[0::1]


Input 2:
    A = "bbaba"
    B = "ab"
Output 2:
    2
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Remove the Substring on Interview Code Editor
Sign Up
to access hints and editorial solutions for Remove the Substring

Discussion


Loading...
Click here to start solving coding interview questions