Problem Statement
Given a String text return the longest prefix which does not have any element of remove as a substring. A substring is a contiguous portion of a string, which may be the entire string. A prefix is a substring taken from the beginning of the string. For example, "wow" is a substring of "awowb", but not a prefix. "awo" is both a substring and prefix of "awowb".
Definition
- Class:
- PrefixChoice
- Method:
- longestPrefix
- Parameters:
- String, String[]
- Returns:
- String
- Method signature:
- String longestPrefix(String text, String[] remove)
- (be sure your method is public)
Constraints
- remove will contain between 1 and 50 elements inclusive.
- Each element of remove will contain between 2 and 50 characters inclusive.
- Each character in each element of remove will be a lowercase letter ('a'-'z').
- text will contain between 1 and 50 characters inclusive.
- Each character in text will be a lowercase letter ('a'-'z').
Examples
"awowb"
{"wow"}Returns: "awo"
The longest prefix is "awo" since anything longer will contain "wow"."awowb"
{"awowb"}Returns: "awow"
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx"
{"abce","abcdefh","abcdefghijklmnopr"}Returns: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx"
"zzzzzzzzzz"
{"zz","zzz","zzzz"}Returns: "z"
"topcodertopcodertopcodertopcoder"
{"rtopcodertop"}Returns: "topcodertopcoderto"