Array Subset of another array 🔥| Brute + Better + Optimal | Array | Love Babbar DSA Sheet | Hindi
Vložit
- čas přidán 27. 07. 2024
- Time Stamps :
Problem discussion : 0:00
Different approaches : 01:40
Approach 1 (Brute Force) : 02:21
Approach 2 (Sorting + Binary Search) : 05:00
Approach 3 (Hashmap) : 06:55
Code explanation : 09:15
Time Complexity : O(n + m)
Space Complexity : O(n)
Problem Link : practice.geeksforgeeks.org/pr...
C++ Code Link : github.com/Ayu-99/Love-Babbar...
Python Code Link: github.com/Ayu-99/Love-Babbar...
Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)
#DataStructuresAndAlgorithms
#LoveBabbarDSASheet
#interviewpreparation
Array Subset of another array solution
Array Subset of another array Leetcode
Array Subset of another array C++
Array Subset of another array C++ Hindi
Array Subset of another array Hindi
Checkout the series: 🔥🔥🔥
👉 Array: • Arrays
👉 Recursion : • Recursion
👉 Stack and Queue : • Stack And Queue
👉 Greedy : • Greedy
👉 Dynamic Programming : • Dynamic Programming
👉 Leetcode contests : • Leetcode contests
👉 Leetcode June Challenge : • Leetcode June Challenge
👉 Leetcode July Challenge : • Leetcode July Challenge
LIKE | SHARE | SUBSCRIBE 🔥🔥😊
string isSubset(int a1[], int a2[], int n, int m) {
//create empty map
unordered_map map;
//dump all a1 elements inside map and give each a count of 1
for(int i=0;i
Thanks for the timestamp. :)
Thank you so much for posting video keep making such a helpfull video 👌😊
In Gfg not accepted mam
Great sharing
New friends
Your videos are just awesome.
Just sharing a another version of the code as the solution you showed in the video is somehow not passing all the test cases
def isSubset(a1, a2, n, m):
l1 = []
check = True
for i in a2:
if not check:
break
else:
if i in a1:
check = True
a1.remove(i)
else:
check = False
if check:
return "Yes"
else:
return "No"
am i only getting error while submitting test case no 51 /209
Thank you 👍
Welcome😊
mam please explain all approaches code solutions also
Nice video
Sister I request you to make an video on stl time complexities
Noted. Thanks :)
Instead of hashmap, can we use hashset? Cz by default u r assigning 1 count for all the keys.
Mam recursion bano na hindhi playlist may 😁😁
In the second approach sorting time complexity of array will also be added.
Mam can yu please make a series related to hash map
💯💯
Second approach Ki complexity nlogn hogi mlogn nhi, kyoki sorting krne me nlogn lag jayega
Didi apne Bina array ke elements ka input liye hi kaise proceed Kiya code me
👌👍
💯💯💯😁
we can do in this approach also,
we take two pointers, one i=0 on a1, and another j=0 on a2, then we iterate i until we reach a1s end
and while iterating we check if j==m, if j==m , break and return yes, else check if a1[i]==a2[j] ,if equal j++;i++ , else only i++
if j==m , return true, else return false.
this approach takes only O(n) , it passed all the test cases for me, let me know if this is the optimised solution.
BTW i liked your binary and hashmap approaches, didnt expect that, thanks.
Pls Say Me Is Cp Necessary??
If you are having problem understanding the problem and thinking of approach in online tests or contests, then yes cp is necessary
@@AyushiSharmaDSA thanks
this code will give error if the size of a2 is greater than a1
string isSubset(int a1[], int a2[], int n, int m) {
sort(a1,a1+n);
sort(a2,a2+m);
int count = 0 ;
int k=0;
for(int i=0;i
Why are using count .simply use one variable k only comparison the m ..and get the results
Suppose you sort both a and b
Like and you sort both
So
Your a= 1 2 3 4
Your b= 1 2 4
Because your also not going to increase ot reach 4