Trains the technique from
LeetCode 321Create Maximum NumberThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two tapes of single digits read first and second. Choose k digits altogether, some from each tape, keeping the digits of each tape in the order they appear on it, and read the chosen digits off as one number of k digits.
Return the largest number obtainable, as the list of its k digits.
Example 1
Three digits in all. Taking 8 and 9 from the first tape and 7 from the second, then merging them, reads 987. Nothing larger is available, since the only 9 sits at the end of the first tape and reaching it costs the 6 in front of it.
Example 2
The first tape holds three nines, which beats anything the second tape could contribute, so all three digits come from there.
Example 3
Both digits are needed, and putting the larger one first reads 21.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_number(first: list[int], second: list[int], k: int) -> list[int]:public int[] maxNumber(int[] first, int[] second, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.