Ctrl K

Shared So Far

Medium
Two judges ranked the same 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.
Example 1
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.

Example 2
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.

Example 3
first=[1], second=[1] → [1]
Constraints
  • 1 ≤ n = len(first) = len(second) ≤ 50
  • first and second are permutations of 1 to n
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMost Different Pair MediumAll Non-Falling Subsequences MediumEight Lamps After Many Nights MediumPalindrome After a Few Fixes MediumGroups of Four at the Cinema Medium
loading Python…
Input
first=[2, 1, 4, 3], second=[1, 2, 3, 4]
Expected
[0, 2, 2, 4]

Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.