You are given two permutations A and B of the integers 1 to n. The prefix common array C has C[i] equal to the number of values that appear in both A[0..i] and B[0..i]. Return C.
You are given two permutations A and B of the integers 1 to n. The prefix common array C has C[i] equal to the number of values that appear in both A[0..i] and B[0..i]. Return C.
Example 1:
Input: {"A":[1,3,2,4],"B":[3,1,2,4]}
Output: [0,2,3,4]
Constraints:
1≤A.length==B.length==n≤50
1≤A[i],B[i]≤n
A and B are both permutations of the integers 1 to n.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"A":[1,3,2,4],"B":[3,1,2,4]}
Keep a counter per value 1..4. A value is common once both prefixes contain it, which is exactly when its counter reaches 2.