Company: Nutanix
Difficulty: medium
The Number Game Given three decimal strings `D`, `E`, and `F`, each of length `L`, form a number `X` by using every digit of `F` exactly once. Find the smallest possible `X` such that: `X` is greater than both `D` and `E`; the reverse of `X` is smaller than the reverse of both `D` and `E`; `X` is not equal to `F`. If no number satisfies all conditions, print `-1`. Input Read `L`, `D`, `E`, and `F` separated by whitespace. Output Print the smallest valid number, or `-1`. Notes All strings have length `L`, contain decimal digits, and do not begin with zero. Use every digit of `F` exactly once.