Тёмный
No video :(

LeetCode 350 | Intersection of Two Arrays II | Solution Explained (Java + Whiteboard) 

Xavier Elon
Подписаться 4,3 тыс.
Просмотров 18 тыс.
50% 1

Today we go over the sort method to solving this problem!
Running Time: O(mlogm + nlogn)
Space Complexity: O(logm + logn)
Always be pluggin:
Slack Channel: join.slack.com...
Github: github.com/xav...
Facebook: / xavier.hollingsworth.3
Instagram: / xavierelon
LinkedIn: / xavier-hollingsworth-5...
Twitter: / elon_xavier

Опубликовано:

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 43   
@fsxaviator
@fsxaviator 3 года назад
Thank you!!! Finally, this was the first explanation I was actually able to understand.
@rusty-coder
@rusty-coder Год назад
Me too
@Priyam6F4
@Priyam6F4 Год назад
Hey. The solution doesn't work for : int[] arr1 = {4,9,5}; int[] arr2 = {9,4,9,8,4}; please check.
@user-tx3jz2id7n
@user-tx3jz2id7n Год назад
Thank you. I have always wondered why there was a pre-increment and a post increment, and this is a perfect use case for post-increment. It's the small things sometimes. I've never seen that before.
@ritchievales
@ritchievales 2 года назад
I had it so close.... I was increasing the indexes depending on nums1 and nums2 sizes... that approach worked for a few testcases but I couldn't figure out until saw this video, thanks! For sure I was not able to solve it by myself but still learned a lot :)
@sayantaniguha8519
@sayantaniguha8519 2 года назад
Finally an explanation using constant space!
@nishukumari8791
@nishukumari8791 4 месяца назад
waw its really simple and awesome
@someshsahu4638
@someshsahu4638 Год назад
Very nice explanation thankyou 🙏🏼🙏🏼🙏🏼
@athangkulkarni8245
@athangkulkarni8245 9 месяцев назад
At max, minimum of size of both arrays can be duplicates, so instead of doing length1 * length2, you can do min(length1, length2)
@HenggaoCai
@HenggaoCai 4 года назад
Keep up the good work! You're doing great.
@ginasomara267
@ginasomara267 2 года назад
nice and understandable!! TY
@sasgaro
@sasgaro 4 года назад
Great video, you definitely deserve more subs, one note: that music started waaaayyy too early and was kinda unexpected covering your voice over.
@xavierelon
@xavierelon 4 года назад
Thanks man. And thanks for the critique I'll be sure to fix it. What do you think about my intro I made? I'm still working on it
@sasgaro
@sasgaro 4 года назад
@@xavierelon I don't usually pay much attention to intros and for me, the best intro is the one I barely notice and I didn't notice yours. Don't get me wrong, I don't mean it in a bad way, on the contrary , I think it's visually great, not irritating like in some channels, and most importantly - short, but people usually come for the content and not for the intros.
@xavierelon
@xavierelon 4 года назад
Serdar Asgarov awesome thank you for the constructive criticism. Make sure you subscribe if you haven’t already hehe
@CD-xd6fm
@CD-xd6fm 3 года назад
@@xavierelon Hey , can you show us how you made your intro bcoz its cool or is it a purchased plugin?
@bina.soche.samjhe
@bina.soche.samjhe Год назад
why did we use nums1 and not nums2 to store the common elements
@pubamx
@pubamx 3 года назад
Great explanation. Just wasn't clear to me why SC is O(logm + long). Is it due to the sort of arrays generates overrides the initial value of nums array or why? Thanks in advance.
@AbhishekKumar-ff9vg
@AbhishekKumar-ff9vg 3 года назад
how to implement the same in c++ with same space com. i tried but more elements are getting copied can you give code for same. thanks for video
@lighto263
@lighto263 2 года назад
Solution without using extra space is amazing thanks! Bit time complexity basically is O(N), isn't it?
@xavierelon
@xavierelon 2 года назад
Yes should be. Did I forget to mention time complexity in this video? Sorry if so
@vikasraaja5760
@vikasraaja5760 2 года назад
Wouldn't it be O(nlogn) because that's the time complexity of Arrays.sort()?
@yogeshyts
@yogeshyts 2 года назад
@@vikasraaja5760 lgta h timeComplexity india m jada matter krti h
@peterpace3379
@peterpace3379 Год назад
​@@yogeshyts of course, har company ke coding round mein aata hai ye sab
@adithyang6672
@adithyang6672 Год назад
What about the values which are already present in nums1 how are they getting deleted
@monikajha3500
@monikajha3500 2 года назад
I am little confused about the third array(ans) size as length1 * length2. Can we take the size as the smallest of length1 and length2?
@monikajha3500
@monikajha3500 2 года назад
Oops ! sorry. I commented before I finished this video...
@Candyroxnrulz
@Candyroxnrulz 2 года назад
wait i still don't get it why
@sayantaniguha8519
@sayantaniguha8519 2 года назад
How is the space *O(log m + log n)* ?
@odongoemmanuel885
@odongoemmanuel885 2 года назад
where are you getting the nums in return Arrays.copyOfRange(nums, 0, k);
@xavierelon
@xavierelon 2 года назад
It’s nums1
@samareshms4591
@samareshms4591 2 года назад
could have optimized to O(mlogm + n)
@qianjun1856
@qianjun1856 2 года назад
Am I missing anything, I feel this algorithm is not working. A=[1,2,2,1,3,2] B=[1,2,3] A_sorted=[1,1,2,2,2,3] expected output: [1,2] The Algorithm will produce[1,2,3]
@longetolulope1549
@longetolulope1549 2 года назад
expected output is actually 1,2,3...d problem is to find intersection, similar-distinct elements in both array
@pqr.priyanshu
@pqr.priyanshu 2 года назад
Which software do you use as a whiteboard?? thanks
@xavierelon
@xavierelon 2 года назад
Goodnotes on my ipad
@pqr.priyanshu
@pqr.priyanshu 2 года назад
@@xavierelon thanks ❤️
@artemvolkov5682
@artemvolkov5682 8 месяцев назад
So smart to add background music while you're unable to articulate well the n/m complexity. I've broken my ears
Далее
Leetcode - Intersection of Two Arrays II (Python)
4:54
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 344 тыс.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Intersection of Two Arrays - Leetcode 349 - Python
4:23
LeetCode Squares of a Sorted Array Explained - Java
8:56