Trains the technique from
LeetCode 88Merge Sorted ArrayThis 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 probes each wrote down signed temperature deltas, and both wrote them in non-decreasing order. The station keeps one long log, the integer array base, which was sized up front to hold both probes' output: its first filled positions carry the deltas the station probe recorded, and the added positions after them are reserve slots. A reserve slot is stored as 0 and carries no reading, so any value you find there is free to overwrite.
The second probe's added deltas arrive in the integer array patch, also in non-decreasing order.
Fold patch into base so that base ends up carrying all filled + added deltas in non-decreasing order. Do it inside base, using no more than a constant amount of extra space, then return base. Note that a delta of 0 is a perfectly ordinary reading, so a position cannot be judged by its value alone; only filled says where the real readings stop.
Example 1
The two reserve slots at the end make room for 1 and 9, which slot in around the existing deltas.
Example 2
Both arriving deltas are colder than everything the station probe logged, so the single existing reading is pushed to the end.
Example 3
The second probe recorded nothing, so there are no reserve slots and the log is already in order.
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 merge_log(base: list[int], filled: int, patch: list[int], added: int) -> list[int]:public int[] mergeLog(int[] base, int filled, int[] patch, int added)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.