Problem Statement
You will be given two Strings pattern and letters, containing uppercase letters ('A' - 'Z'). pattern can contain also several '?', representing hidden characters. You are to return the lexicographically earliest string which can be derived from pattern by replacing each '?' character with a character from letters. Each character from letters can be used only once per occurrence in letters.
Definition
- Class:
- PatternFiller
- Method:
- fill
- Parameters:
- String, String
- Returns:
- String
- Method signature:
- String fill(String pattern, String letters)
- (be sure your method is public)
Notes
- If letters contains several identical characters, each of them can be used exactly once (see example 1).
Constraints
- pattern will contain between 1 and 50 characters, inclusive.
- Each character in pattern will be an uppercase letter ('A' - 'Z') or '?'.
- letters will contain between Q and 50 characters, inclusive, where Q is the number of '?'s in pattern.
- Each character in letters will be an uppercase letter ('A' - 'Z').
Examples
"AB??ACA?BA"
"GRAYCODE"
Returns: "ABACACADBA"
"??T?"
"SEASEA"
Returns: "AATE"
"A??A"
"BABA"
Returns: "AAAA"
"AB?SF?G??F???"
"ABACABA"
Returns: "ABASFAGAAFBBC"
"?NJOYTHECONTE??"
"TSE"
Returns: "ENJOYTHECONTEST"