PrefPref

3.7

51 votes
Ad-Hoc, Approved, Easy, Open, String Manipulation, Two pointer
Problem

You are given two string S and T. Find the maximal length of some prefix of the string S which occurs in strings T as subsequence.

Input
The first line contains string S. The second line contains string T. Both strings consist of lowecase Latin letters.

Output
Output one integer - answer to the question.

Constraints
1 <= length of S, T <= 106

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?