Class Solution
-
- All Implemented Interfaces:
public final class Solution
3474 - Lexicographically Smallest Generated String.
Hard
You are given two strings,
str1
andstr2
, of lengthsn
andm
, respectively.A string
word
of lengthn + m - 1
is defined to be generated bystr1
andstr2
if it satisfies the following conditions for each index0 <= i <= n - 1
:If
str1[i] == 'T'
, the substring ofword
with sizem
starting at indexi
is equal tostr2
, i.e.,word[i..(i + m - 1)] == str2
.If
str1[i] == 'F'
, the substring ofword
with sizem
starting at indexi
is not equal tostr2
, i.e.,word[i..(i + m - 1)] != str2
.
Return the lexicographically smallest possible string that can be generated by
str1
andstr2
. If no string can be generated, return an empty string""
.Example 1:
Input: str1 = "TFTF", str2 = "ab"
Output: "ababa"
Explanation:
The strings
"ababa"
and"ababb"
can be generated bystr1
andstr2
.Return
"ababa"
since it is the lexicographically smaller string.Example 2:
Input: str1 = "TFTF", str2 = "abc"
Output: ""
Explanation:
No string that satisfies the conditions can be generated.
Example 3:
Input: str1 = "F", str2 = "d"
Output: "a"
Constraints:
<code>1 <= n == str1.length <= 10<sup>4</sup></code>
1 <= m == str2.length <= 500
str1
consists only of'T'
or'F'
.str2
consists only of lowercase English characters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final String
generateString(String str1, String str2)
-
-
Method Detail
-
generateString
final String generateString(String str1, String str2)
-
-
-
-