Trains the technique from
LeetCode 2956Find Common Elements Between 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 crates of tokens have been logged. left lists the colour code of each token in the first crate and right does the same for the second crate.
Return a two-entry array [a, b], where
a is the number of positions i in left whose code appears somewhere in right, andb is the number of positions j in right whose code appears somewhere in left.How often a code is repeated in the other crate does not matter, only whether it is there at all. Positions are counted one by one, so a crate that holds the same code three times can contribute three to its tally.
Example 1
Code 1 sits at two positions of the first crate and appears in the second, so the first tally is 2. Code 2 does not appear in the second crate. Looking the other way, only the single 1 in the second crate has a match, so the second tally is 1.
Example 2
Both crates hold codes 5 and 6, so every position of both crates counts: three in the first crate and four in the second.
Example 3
The crates have no code in common, so both tallies are 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_tallies(left: list[int], right: list[int]) -> list[int]:public int[] sharedTallies(int[] left, int[] right)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.