Question: String Obsession Problem Description Who knows the reason for why little Meera is so obsessed with strings and loves to spend her time analyzing them!?
String Obsession
Problem Description
Who knows the reason for why little Meera is so obsessed with strings and loves to spend her time analyzing them!?
Meera has an everlasting passion for strings. One day, she took a string let us call it the main string along with some substrings and decided to remove as many substrings from the main string as possible. Whenever a part is removed, the remaining portions of the string are joined together. For example, if the main string is "hello" and el is removed, it becomes "hlo." Note that she can remove one substring only once from the string.
Given the main string and the substrings, determine and print the maximum number of substrings that can be removed.
Constraints
length of main string
length of each substring
Both main and substrings will be having only lowercase alphabets only.
Input
First line consists of N denoting the total number of substrings.
Next line consists of N space separated substrings.
Last line consists of the main string.
Output
Print a single integer denoting the maximum number of substrings that can be removed.
Time Limit secs
Examples
Example
Input
hd el llo wor ell lds
helloworlds
Output
Explanation
Given main string is helloworlds
Remove llo, the string becomes heworlds
Remove wor, the string becomes helds
Remove el the string becomes hds
Remove hd the string becomes s One cannot remove anything further.
Hence the maximum number of substrings we can remove is print as output.
Example
Input
ggc rm oo le glh oog ec
googlechrome
Output
Explanation
Given main string is googlechrome
Remove oo the string becomes gglechrome
Remove le the string becomes ggchrome
Remove ggc the string becomes hrome. One cannot remove anything further.
Second possibility can also be removing ecglhoo resulting in grome, further reduction is impossible. In this case also only substrings have been removed.
Hence the maximum number of substrings we can remove is hence print as output.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
