Minimum string#11092

Minimum string (Editorial)

The lexicographically smallest letters can always be inserted into string (at any position) using the described operation.

Let's combine strings and . Let s = a + b. Sort the letters of string in ascending order. The lexicographically smallest letters will be at the beginning of string . If string contains letters, the password will be the prefix of string of length .

Algorithm implementation

Read the input strings and .

cin >> a;
cin >> b;

Combine strings and and sort the resulting string.

s = a + b;
sort(s.begin(), s.end());

Print the answer — the prefix of string with a length equal to a.size().

cout << s.substr(0, a.size());

Python implementation

Read the input strings and .

a = input()
b = input()

Combine strings and .

s = a + b

Sort the string .

s = ''.join(sorted(s))

Print the answer — the prefix of string with a length equal to .

print(s[:len(a)])