Find the Prefix Common Array of Two Arrays | 3 Detailed Approach | Leetcode 2657 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
Hi Everyone, this is the 135th video of our Playlist "Arrays 1D/2D : Popular Interview Problems".
Now we will be solving a good practice problem based on Array - Find the Prefix Common Array of Two Arrays | 3 Approaches | Brute Force | Better | Optimal | Leetcode 2657 | codestorywithMIK
I will also code all the 3 approaches in Java , hence the video might be lengthy, but I really hope it helps you all.
Problem Name : Find the Prefix Common Array of Two Arrays | 3 Approaches | Brute Force | Better | Optimal | Leetcode 2657 | codestorywithMIK
Company Tags : will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Find the Prefix Common Array of Two Arrays.cpp
Leetcode Link : https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Segment Tree Concepts Playlist : • Segment Tree | Introduction | Basics ...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
Trie Playlist - • Word Search II (Google, Amazon, Meta,...
Difference Array Technique: Concepts & Qns : • Introduction | What | How | Differenc...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Video Summary :
Approach 1 (Brute Force):
The brute force approach iterates over each prefix of the arrays A and B and checks if elements in A are present in B up to the current index. This involves nested loops, leading to a time complexity of O(n3). The idea is straightforward but inefficient due to repeated comparisons.
Approach 2 (Better Approach):
This approach uses two boolean arrays to track which numbers have appeared in A and B up to the current index. For each prefix, it checks all numbers to count common elements. While still checking all numbers for each prefix, the use of auxiliary arrays reduces the complexity to O(n2).
Approach 3 (Optimal Approach):
The optimal approach leverages a hash map to track the frequency of elements from both arrays. When an element's frequency reaches 2, it indicates it is common in the prefix. This approach avoids redundant checks and achieves a linear time complexity of O(n), making it the most efficient solution.
✨ Timelines✨
00:00 - Introduction
00:31 - Motivation
01:31 - Problem Explanation
05:01 - Brute Force O(n^3)
11:13 - Better Approach O(n^2)
19:38 - Best Approach O(n)
29:15 - Coding Approach-1 in C++
31:34 - Coding Approach-2 in C++
33:46 - Coding Approach-3 in C++
34:53 - Coding Approach-1 in JAVA
35:59 - Coding Approach-2 in JAVA
37:14 - Coding Approach-3 in JAVA
#MIK #mik #Mik
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik