From 3e7fff82d7ebe0daa9a30d8c998080a66f59ed3d Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Tue, 14 Jan 2025 22:17:16 +0530 Subject: [PATCH] Create 2657. Find the Prefix Common Array of Two Arrays --- 2657. Find the Prefix Common Array of Two Arrays | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 2657. Find the Prefix Common Array of Two Arrays diff --git a/2657. Find the Prefix Common Array of Two Arrays b/2657. Find the Prefix Common Array of Two Arrays new file mode 100644 index 0000000..0346001 --- /dev/null +++ b/2657. Find the Prefix Common Array of Two Arrays @@ -0,0 +1,15 @@ +class Solution { +public: + vector findThePrefixCommonArray(vector& A, vector& B) { + int n = A.size(), common = 0; + vector result(n), count(n + 1, 0); + + for (int i = 0; i < n; ++i) { + if (++count[A[i]] == 2) ++common; + if (++count[B[i]] == 2) ++common; + result[i] = common; + } + + return result; + } +};