n contestants, numbered 1 to n: first is the order of the first judge, second the order of the second. Both arrays are permutations of 1 to n.
For each i, count how many contestants are within the top i + 1 places of **both** judges. Return these counts as an array of length n.first=[2, 1, 4, 3], second=[1, 2, 3, 4] → [0, 2, 2, 4]
After 1 element nothing is shared; after 2, both have 1 and 2; after 3 still just 1 and 2 (4 and 3 are on different sides); after 4 everything is shared.
first=[3, 1, 2], second=[3, 2, 1] → [1, 1, 3]
3 opens both lists; 1 and 2 only become shared at the last step.
first=[1], second=[1] → [1]
first and second are permutations of 1 to nfirst=[2, 1, 4, 3], second=[1, 2, 3, 4]
[0, 2, 2, 4]
Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.