IBM Backend OA
Anonymous User
170

Two strings are given, word and substr. Some of the characters in word are a question mark (?). Find the lexicographically smallest string that can be obtained by replacing'?' characters such that substr appears at least once. If it is not possible to do so, return "-1".

Note: A substring is a contiguous sequence of characters within a string. For example, "bcd" is a substring of "abcde" but "ac" is not. For two strings a and b of the same length, a is lexicographically smaller than b if a, b, for some 0s i</al, and a = by for all 0 sj<.Exampleword = "as?b?e?gf" substr = "dbk". Replace the 3rd and 5th characters with 'd' and 'k' to get "asdbke?gf which has substr = "dbk" as a substring.

Replace the remaining?' with 'a'. The final string is "asdbkeagf"

Sample

Word = ??aba???ac

Substr = abab

Output = aaababaaac

Word = ??ac???ac?

Substring= acb

Output = aaacaaaacb

Comments (3)