Problem Statement
PROBLEM STATEMENT A string k is a subsequence of a string x if the letters of k appear in order in x. i.e., "abc" is a subsequence of "azzzzbzzzzc". "abc" is also a subsequence of "abc" and of "abcabc". However, "abc" is not a subsequence of "acb", since the letters to not appear in order. DEFINITION Class name: Compare Method name: shortest Parameters: String, String Returns: String Method signature (make sure it is declared public): String shortest(String tofind, String base); Given two Strings, you must determine what the shortest substring of base that contains tofind as a subsequence. If multiple substrings of the same shortest length exist, return the one that occurs first in base. If the tofind subsequence does not exist in base, return the empty string "". TopCoder will enforce the following restrictions: * tofind will be between 1 and 6 characters, inclusive. * base will be between 1 and 12 characters, inclusive. * tofind and base will contain only lowercase letters (a-z). EXAMPLES tofind = "abc" base = "aabbc" There are two substrings containing "abc" as a subsequence: "aabbc", and "abbc" Since "abbc" is shorter, method returns "abbc". tofind = "ab" base = "efaefbeecc" method returns "aefb". tofind = "abc" base = "abeecacabffc" method returns "abeec". Note that "abffc" is also valid and of the same length, but "abeec" occurs first, and thus is the correct answer. tofind = "aid" base = "abidhelloaid" method returns "aid".
Definition
- Class:
- Compare
- Method:
- shortest
- Parameters:
- String, String
- Returns:
- String
- Method signature:
- String shortest(String param0, String param1)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.