You are not logged in. Please login at www.codechef.com to post your questions!

×

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

This question is marked "community wiki".

asked 03 Apr '16, 14:09

ishpreet's gravatar image

4★ishpreet
9718
accept rate: 0%

edited 04 Apr '16, 15:15

admin's gravatar image

0★admin ♦♦
19.8k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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