left and right of lowercase English letters. Build a new string: while at least one of them is non-empty, remove the first letter of left or of right (either non-empty one) and append it to the result. Every letter ends up used exactly once, and the order of letters within each original string is preserved.
Return the lexicographically largest result you can build this way.left="bad", right="cab" → 'cbadab'
Take c from right, then b from left (the remainder bad beats ab). Since ad beats ab, the next two letters a and d come from left, and ab closes the string: cbadab.
left="zz", right="y" → 'zzy'
Both z letters are best placed at the front.
left="aab", right="aac" → 'aacaab'
left="bad", right="cab"
'cbadab'
Run checks the first 3 tests in your browser. Submit checks all 139 tests on the server, hidden ones included.