Tap here to switch tabs
Problem
Submissions

Problem: Find the Prefix Common Array of Two Arrays

med
30 min
Try to solve the Find the Prefix Common Array of Two Arrays problem.

Statement

Given two integer arrays A and B of equal length n, define an array C of length n such that for each index i, C[i] equals the count of values that appear in both prefixes A[0..i] and B[0..i] (count each value at most once).

Return the array C.

Note: A and B are permutations of the integers from 11 to n.

Constraints:

  • 1≤1 \leq A.length ==== B.length ==== n ≤50\leq 50

  • 1≤1 \leq A[i], B[i] ≤\leq n

  • It is guaranteed that A and B are both a permutation of n integers.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Prefix Common Array of Two Arrays

med
30 min
Try to solve the Find the Prefix Common Array of Two Arrays problem.

Statement

Given two integer arrays A and B of equal length n, define an array C of length n such that for each index i, C[i] equals the count of values that appear in both prefixes A[0..i] and B[0..i] (count each value at most once).

Return the array C.

Note: A and B are permutations of the integers from 11 to n.

Constraints:

  • 1≤1 \leq A.length ==== B.length ==== n ≤50\leq 50

  • 1≤1 \leq A[i], B[i] ≤\leq n

  • It is guaranteed that A and B are both a permutation of n integers.