×

Author: Ishpreet
Tester: Karan

# 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

This question is marked "community wiki".

4★ishpreet
9718
accept rate: 0%

19.8k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,680
×3,766
×948
×14
×8
×2

question asked: 03 Apr '16, 14:09

question was seen: 881 times

last updated: 04 Apr '16, 15:15