349. Intersection of Two Arrays | 4 Approaches | Sorting | 2 Pointer | Hash Set | Binary Search
Вставка
- Опубліковано 25 сер 2024
- In this video, I'll talk about how to solve Leetcode 349. Intersection of Two Arrays | Sorting | 2 Pointer | Hash Set | Binary Search
Checkout DSA-169 Series: • Aryan DSA-169 Series |...
100Days 100k Placements: • 100 Days 100K Placement
Let's Connect:
📝Linkedin: / aryan-mittal-0077
📸 Instagram: / ez.pz.dsa
📱Telegram : t.me/aryan_mit...
🤖 Github: github.com/ary...
About Me:
I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
✨ Timelines✨
✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms
The amount of easy problems lately, gives me a feeling of much Harder problems coming soon 🔜🫠
We are also waiting for 30-50 minutes long videos coming soon 🔜 🌝
Yes same here.
For me the intuitive approach was: Use Map add all elements from the smaller array. The key of the map is the element, the value of the map is the element's occurrence. Then Iterate over the larger one, if it contains the key in the map, first decrement it''s occurrence, if it's 0 remove the key from the map and add the element to the result in both cases. The runtime complexity is O(n + m) and you can solve it fast this way. Btw for cleaner code to take the smaller array you can make a check at the top of the method and return the method with swapped array params. e.g. if (nums1.length > nums2.length) { return intersect(nums2, nums1) }, the intersect is the name of the method.
At 11:30
Wanna ask
Meaning, we add a checker at top, which is smaller size (nums1 size or nums2 size), take the smaller one and store into hashset?
This will improve the space complexity?
Aryan bro when can we get the solution of today's leetcode problem 3 and 4 ?
i think the 3rd one was pretty much easy today
still i got a WA on it in first try
@@abde3394 can you tell your approach ?