PROBLEM STATEMENT
You are given two strings s1 and s2. Each string contains some letters and exactly one asterisk
('*').
You must replace each asterisk with a sequence of letters (possibly of zero length). The resulting
two strings must be equal.
Return the shortest possible resulting string. If it is impossible to make the strings equal,
return "impossible" (quotes for clarity) instead.
DEFINITION
Class:TwoStringMasks
Method:shortestCommon
Parameters:string, string
Returns:string
Method signature:string shortestCommon(string s1, string s2)
CONSTRAINTS
-s1 will contain between 1 and 50 characters, inclusive.
-s2 will contain between 1 and 50 characters, inclusive.
-s1 and s2 will contain only uppercase letters ('A'-'Z') and asterisks ('*').
-s1 and s2 will contain exactly one asterisk each.
EXAMPLES
0)
"TOPC*DER"
"T*PCODER"
Returns: "TOPCODER"
Each of the asterisks should be replaced with an "O".
1)
"HELLO*"
"HI*"
Returns: "impossible"
No matter how you replace the asterisks, the second characters of the strings will differ. So it
is impossible to make the strings equal.
2)
"GOOD*LUCK"
"*"
Returns: "GOODLUCK"
The first asterisk should be replaced with an empty string.
3)
"*SAMPLETEST"
"THIRDSAMPLE*"
Returns: "THIRDSAMPLETEST"
4)
"*TOP"
"*CODER"
Returns: "impossible"
5)
"*"
"A*"
Returns: "A"
6)
"*A"
"B*"
Returns: "BA"
7)
"LASTCASE*"
"*LASTCASE"
Returns: "LASTCASE"
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.