×

# TSECJ103 - Editorial

Contest

Author: Full name

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.

142
accept rate: 0%

I wrote a recursive solution too.

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

question asked: 30 Jul '17, 16:54

question was seen: 195 times

last updated: 30 Jul '17, 16:58