Find Prefix Common Array Of Two Arrays
We can solve this problem by iterating over two arrays A and B while keeping track of numbers that have occurred at or before the current index in both arrays using two hash sets (or arrays).
2657. Find the Prefix Common Array of Two Arrays Difficulty: Medium Topics: Array, Hash Table, Bit Manipulation You are given two 0-indexed integer permutations A and B of length n. 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. Return the prefix common array of A and B. A sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once. Example 1: Input: A = [1,3,2,4], B = [3,1,2,4] Output: [0,2,3,4] Explanation: At i = 0: no number is common, so C[0]...