Trains the technique from
LeetCode 1470Shuffle the 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.
A flow logger keeps one batch in a single flat list readings of length 2 * half. The
first half entries are the intake figures for pairs 0, 1, ..., half - 1 in that order,
and the last half entries are the outflow figures for the same pairs in the same order, so
readings[half + i] is the outflow that belongs with the intake readings[i].
Rebuild the batch pair by pair: the intake of pair 0, then the outflow of pair 0, then the intake of pair 1, then the outflow of pair 1, and so on to the last pair.
Return the rebuilt list, which holds the same 2 * half figures in that paired order.
Example 1
The intake figures are 3, 7 and 2 and the outflow figures are 9, 4 and 1, so pair 0 reads 3 then 9, pair 1 reads 7 then 4, and pair 2 reads 2 then 1.
Example 2
Intake 5 belongs with outflow 2, intake 4 with outflow 1, and intake 3 with outflow 6.
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 interleave_halves(readings: list[int], half: int) -> list[int]:public int[] interleaveHalves(int[] readings, int half)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.