Generate Lexicographically Smallest String

Asked at Deutsche Bank · Coding Questions · Difficulty: Hard · Last asked Jul 15, 2026

String S1 of length L1 consisting of uppercase alphabets only. String S2 of length L2 consisting of characters 'T' and 'F' only. Generate a lexicographically smallest string S of length (L1 + L2 - 1) such that a substring of length L1 in string S starting at index i (0 <= i < L2) is equal to S1 if and only if ith element of S2 is 'T'. If generating a string is not possible return -1.

Loading the problem…