Trains the technique from
LeetCode 2657Find the Prefix Common Array of Two ArraysThis 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 crews unload the same n crates, tagged 1 through n. Each crew works through all the crates in its own order: crewA[i] is the crate the first crew handles in minute i, and crewB[i] is the crate the second crew handles in that same minute. Both lists are permutations of 1 through n.
At the end of every minute the yard manager writes down how many crates have by then been handled by both crews, counting everything either crew touched from minute 0 up to and including the current minute.
Return the manager's log as a list of n numbers, where entry i is the figure recorded at the end of minute i.
Example 1
After minute 0 the crews have handled crates {4} and {1}, with nothing in common. After minute 1 they hold {4, 1} and {1, 4}, so both crates count. Minute 2 adds crate 2 for the first crew and crate 3 for the second, neither of which the other crew has yet. Minute 3 finishes every crate.
Example 2
Both crews start on crate 2, so the first figure is 1. Minute 1 adds crate 1 and crate 5, still leaving only crate 2 shared. Minute 2 gives the first crew crate 5 and the second crew crate 1, so crates 1, 2 and 5 are now shared.
Example 3
Nothing overlaps for the first two minutes. After minute 2 the crews hold {3, 2, 1} and {4, 1, 2}, sharing crates 1 and 2.
Example 4
With one crate, both crews handle it in minute 0.
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 shared_progress(crewA: list[int], crewB: list[int]) -> list[int]:public int[] sharedProgress(int[] crewA, int[] crewB)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.