CF222 - Editorial

PROBLEM LINK:

Practice
Contest

Author: Ishpreet
Tester: Karan

DIFFICULTY:

EASY ADHOC

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.

EXPLANATION:

In the problem, we are given two strings S and T. We need to find the largest prefix of S that is a subsequence of T.

Clearly, In this problem, we just need to have one variable len having value of largest prefix and one variable pos for iterating string T, whenever we find the same alphabet as S in T, we increment our len variable.
Pseudo code:
solve()
{
  while(len < s.length() and pos < t.length()) {
  if(s[len]==t[pos]) {
len++ }
  pos++;
  }
}

TESTER’S SOLUTION:

Ideone