#3474

Lexicographically Smallest Generated String

international master · 1950 · lc hard +32 · 31.6% accepted · 31 likes · top 9%

Description

Strings str1 (length n) and str2 (length m) define a target string word of length n + m - 1. For every index 0 <= i <= n-1:

- When str1[i] == \'T\', the length-m slice of word beginning at i must equal str2.

- When str1[i] == \'F\', that slice must differ from str2.

Return the lexicographically smallest word satisfying all constraints, or "" if none exists.

Code

1
2
3