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

×

TSECJ103 - Editorial

PROBLEM LINK:

Contest

Author: Full name

DIFFICULTY:

Easy-Medium

PROBLEM:

Find if a string S splits completely into two strings s1 and s2, the order of characters in s1 and s2 being same as that in S.

QUICK EXPLANATION:

Given a string S made out of s1 and s2, the first character of s must be the first character of s1 or s2. If this isn't true, the answer is NO. If it is true, we can check from the next index of S and the remaining portion of s1 and s2.

EXPLANATION:

We can consider a recursive solution where the base cases are: "" can be formed out of "" and "" -> answer is YES. If S is "" but s1 and s2 are not null, then S does not split completely into s1 and s2 -> answer is NO. If S is "" but s1 and s2 are not null, then S does not split completely into s1 and s2 -> answer is NO.

For the recursion, if S[0]==s1[0], answer could be recursively obtained by considering substring of S and s1. Similarly for s2. If the first character of S does not equal p1[0] or p2[0], the answer is NO.

AUTHOR'S SOLUTIONS:

Author's solution can be found here.

asked 30 Jul '17, 16:54

tseccodecell's gravatar image

0★tseccodecell
142
accept rate: 0%

I wrote a recursive solution too.

(30 Jul '17, 16:58) dhruvsomani3★
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
×1,672
×643
×7
×2

question asked: 30 Jul '17, 16:54

question was seen: 195 times

last updated: 30 Jul '17, 16:58