2657. Find the Prefix Common Array of Two Arrays Medium
1/**
2 * [2657] Find the Prefix Common Array of Two Arrays
3 *
4 * You are given two 0-indexed integer permutations A and B of length n.
5 * A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B.
6 * Return the prefix common array of A and B.
7 * A sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: A = [1,3,2,4], B = [3,1,2,4]
12 * Output: [0,2,3,4]
13 * Explanation: At i = 0: no number is common, so C[0] = 0.
14 * At i = 1: 1 and 3 are common in A and B, so C[1] = 2.
15 * At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
16 * At i = 3: 1, 2, 3, and 4 are common in A and B, so C[3] = 4.
17 *
18 * <strong class="example">Example 2:
19 *
20 * Input: A = [2,3,1], B = [3,1,2]
21 * Output: [0,1,3]
22 * Explanation: At i = 0: no number is common, so C[0] = 0.
23 * At i = 1: only 3 is common in A and B, so C[1] = 1.
24 * At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= A.length == B.length == n <= 50
30 * 1 <= A[i], B[i] <= n
31 * It is guaranteed that A and B are both a permutation of n integers.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/
37// discuss: https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn find_the_prefix_common_array(a: Vec<i32>, b: Vec<i32>) -> Vec<i32> {
43 vec![]
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2657() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.