Prefix Common Array

You are given two permutations A and B of integers from 1 to n. For each index i, count how many distinct values have appeared in both A[0..i] and B[0..i] up to that position. Return the array of these prefix counts.

Examples
Input: [[1,3,2,4],[3,1,2,4]]
Output: [0,2,3,4]
Hints

Prefix Common Array

You are given two permutations A and B of integers from 1 to n. For each index i, count how many distinct values have appeared in both A[0..i] and B[0..i] up to that position. Return the array of these prefix counts.