Smallest Permutation Above a Lower Bound
Asked at Airbnb
Reported by the problem's creator, not verified
You are given the digits of a number as a list, and a lower bound. Rearrange all of the digits, each used exactly once, into the smallest number that is at least the lower bound.
Write smallest_permutation(digits, lower_bound).
Examples
Example 1
Input: digits =
[7,1,8], lower_bound =719Output:
781Explanation: Of the rearrangements of 7, 1 and 8, 718 is below 719 and 781 is the smallest that reaches it.
Example 2
Input: digits =
[1,7,8], lower_bound =200Output:
718Explanation: 178 and 187 are below 200, and 718 is the smallest rearrangement of 1, 7 and 8 that reaches it.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.