Тёмный
No video :(

Build a Matrix With Conditions - Leetcode 2392 - Python 

NeetCodeIO
Подписаться 176 тыс.
Просмотров 9 тыс.
50% 1

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

 

6 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 51   
@rahulsbhatt
@rahulsbhatt Месяц назад
Happy Guru Purnima @NeetCodeIO Thank you so much for everyting!
@harithak9459
@harithak9459 Месяц назад
You are my guru in coding. Happy Guru poornima Sir🎉 I cracked phone screen round of google. Now, i am gonna take onsite rounds. Thanks for sharing the knowledge @neetcode
@E1an9640
@E1an9640 Месяц назад
Hi If u dont mind can u share how u reached till the phone screen round . I am actually applying to lot of jobs recently but have been finding it hard to get an interview atleast. So any advice from u will be helpful .btw all the best for ur upcoming rounds
@anandsahoo3711
@anandsahoo3711 Месяц назад
so proud of you bro
@gavinebenezer1670
@gavinebenezer1670 Месяц назад
I’m cooked 💀
@vaxxnsh
@vaxxnsh Месяц назад
we're all cooked
@advaitdongre
@advaitdongre Месяц назад
Fr
@anujyouthoob
@anujyouthoob Месяц назад
I'm on a 99 day daily challenge streak and Neetcode has played a big role in it
@freecourseplatformenglish2829
@freecourseplatformenglish2829 Месяц назад
Solved it on my own. Yesterday I solved 4 problem on topic Topological sort from Neetcode and it turns out this problem can be easily solved using topological sort. Thanks Navdeep for Neetcode and Happy Guru Poornima 🎉
@aadil4236
@aadil4236 Месяц назад
Great Problem. I solved it after seeing Topological sort under Hints. Really good problem. You have taught me everything Navdeep. Thank you.
@selfhelpguy5589
@selfhelpguy5589 Месяц назад
Happy Guru Purnima Navdeep sir!💐 Your videos have motivated and helped me whenever needed, to complete the July leetcode challenge so far and I have loved to see your approaches even if I was able to solve the problems myself. July leetcode badge coming soon. Thank you so much for all of your great content!
@tranminhquang4541
@tranminhquang4541 Месяц назад
I'm preparing for ICPC regional . I can't thank you enough man. You're a legend!
@SarweshParsewar
@SarweshParsewar Месяц назад
That was really a impressive use of topological sorting who would have thought we can use that algorithm in this question Nice solution as always @NeetCodeIO happy Guru Purnima🎉
@ayanpatel_98
@ayanpatel_98 Месяц назад
Can someone please explain that why it doesn't work for disjoint graph? Can you please provide a working example that why this it doesn't work?
@NeetCodeIO
@NeetCodeIO Месяц назад
Topological sort should work on a disjoint graph. A single dfs wouldn't because you can't cover all nodes from a single source, since the graph isn't connected
@satyamjha68
@satyamjha68 Месяц назад
Solved it !
@viveksoni3269
@viveksoni3269 Месяц назад
The topological sort algo was a good one, I used to do it by maintaining an in-degree vector.
@chien-yuyeh9386
@chien-yuyeh9386 Месяц назад
Thanks for sharing 🎉
@NEO-wl9ox
@NEO-wl9ox Месяц назад
Thanks bro , bro prodigiously got them across to us pretty well, this problem is such an overwhelmingly hard for me and i couldn't have just coped with this without your aid
@yash-uy5ym
@yash-uy5ym Месяц назад
Within 8 mins i understood what the problem was asking and it's because of your amazing explanation. I know topo sort but my mind couldn't think of it until i watched your video You're just too good at teaching❤
@JamesBond-mq7pd
@JamesBond-mq7pd Месяц назад
it's even hard to copy!
@emmanuelidoko1694
@emmanuelidoko1694 Месяц назад
Really good stuff Thankyou so much Neetcode
@anandsahoo3711
@anandsahoo3711 Месяц назад
dayum bro hell of a experience this question was
@rameezalipacific
@rameezalipacific Месяц назад
I'm from Pakistan and currently pursuing a degree in software engineering. Alongside my studies, I'm dedicating significant time to mastering data structures and algorithms (DSA). However, I'm uncertain if excelling in DSA alone is enough to secure a job at top tech companies like the one you work for. Do I need to develop additional skills, such as web, app, or game development, to increase my chances of success? Also, could you share your experience on when you started focusing on DSA-was it during your degree or afterward?
@GeetainSaar
@GeetainSaar Месяц назад
happy guru purnima. guru ji make app development adroid projects free
@anandsrikumar007
@anandsrikumar007 Месяц назад
Thank you
@pastori2672
@pastori2672 Месяц назад
i used a graph and a bfs with the same steps but didnt pass for some reason 😑 if they seriously made it so that only this algorithm passes thats extremely lame
@rostislav_engineer
@rostislav_engineer Месяц назад
thanks for this!
@ayushmandash948
@ayushmandash948 Месяц назад
Although the explanation was concise but one thing that I still cant understand in the example is, what exactly is preventing 3 and 1 from occurring in the same row coz at the end of the day, 3 and 1 jst need to be above 2 (row-wise) and 3->2->1 (column wise) right?? Please help me with this
@NeetCodeIO
@NeetCodeIO Месяц назад
Hmm, I'm not at my desk right now but you might be right, I think it might be possible to have valid solutions the way you describe.
@aashishbathe
@aashishbathe Месяц назад
Yeah, as per my understanding, it can be in the same row, but for our simplicity we are assuming different rows. It can be in same row, as long as that row is strictly above the row in which second element is.
@tranminhquang4541
@tranminhquang4541 Месяц назад
I think he assumes they are in different rows for simplicity. That way , we can still fit every number in the matrix and have a valid solution. Because we have k rows and k columns for k numbers so even each number has a unique row and column , it's still possible .
@nihalbhandary162
@nihalbhandary162 Месяц назад
Nothing you would be right. But the solution is easier to code this way, because topSort will put the roots one after another,
@micorlov4321
@micorlov4321 Месяц назад
For top sort both variants 1-3-2 and 3-1-2 are valid. But for our result only 3-1-2 fits. It seems just a luck that we choose 3-1-2. Place for possible bug. What do you think?
@tuandino6990
@tuandino6990 Месяц назад
Im so happy to solve this
@manojvn2612
@manojvn2612 Месяц назад
Sir can you pls suggest me how to get intuition about this ,like how did you understood it was a topological sort question
@NeetCodeIO
@NeetCodeIO Месяц назад
Mainly because it felt similar to course schedule and alien dictionary. Not saying it's easy of course.
@codingmickey
@codingmickey Месяц назад
hey NeetCode(I know the real name but I love calling you that lol) great video and solution :D Thanks for this I had a doubt on 19:04 that you mentioned there will always exist the number in the rowOrder/colOrder if they're not empty(which is meant for they having a cycle) but what if they don't have a condition in the rowConditions/colConditions as given in the 2nd example of Leetcode problem statement :? what if there isn't any condition associated with a number that they can be placed anywhere in the matrix without any restrictions that we should check right? This is the part I'm confused with 😕
@NeetCodeIO
@NeetCodeIO Месяц назад
since in the topological sort we attempt to run a DFS from every source (1 through K), we should be able to collect every single one, even in a disjoint graph.
@codingmickey
@codingmickey Месяц назад
@@NeetCodeIO Thanks for the reply!🫡 My question was, what if the node isn't present in any of the disjoint graphs meant as k=3 rowConditions=[[1,2]] colConditions=[[2,1]] 3 isn't present anywhere so where should it be placed? I mean I couldn't see this condition that these row/colConditions would have all the nodes in them
@codingmickey
@codingmickey Месяц назад
OHH my bad lmao +_+ > The two arrays contain integers from 1 to k. didn't see this line from the problem anyways thanks for replying neetcode.. have a great day :D
@arihantsinghrana2173
@arihantsinghrana2173 Месяц назад
Break means no more daily uploads ?
@NeetCodeIO
@NeetCodeIO Месяц назад
I'll be back for tomorrow
@arihantsinghrana2173
@arihantsinghrana2173 Месяц назад
@@NeetCodeIO thank the lord 🙌🙌
@arihantsinghrana2173
@arihantsinghrana2173 Месяц назад
And yeah happy Guru Purnima @NeetCodeIO 😁
@hithambasheir3283
@hithambasheir3283 Месяц назад
Stopped after getting the intuition and came up with this #Cross topological sort def get_topological_sort(adjList, n): indegree = [0] * n nexts = defaultdict(list) for i, j in adjList: j -= 1 i -= 1 indegree[j] += 1 nexts[i].append(j) q = [] for i, j in enumerate(indegree): if j == 0: q.append(i) res = [] while q: record = q.pop(0) res.append(record + 1) for nxt in nexts[record]: indegree[nxt] -= 1 if indegree[nxt] == 0: q.append(nxt) return [] if len(res) != n else res rows_topo = get_topological_sort(rowConditions, k) if not rows_topo: return [] cols_topo = get_topological_sort(colConditions, k) if not cols_topo: return [] res = [[0 for _ in range(k)] for _ in range(k)] idx_pair = defaultdict(list) for i, j in enumerate(rows_topo): idx_pair[j].append(i) for i, j in enumerate(cols_topo): idx_pair[j].append(i) for num in idx_pair: i, j = idx_pair[num] res[i][j] = num return res
@iliadmitriev01
@iliadmitriev01 Месяц назад
Since we all got things to do and places to be 😂😂😂😂
@user-vk6ov4it8q
@user-vk6ov4it8q Месяц назад
prefer khans algo for toposort
@abhilashpatel6852
@abhilashpatel6852 Месяц назад
I bet you're confused why you suddenly being called guru today😂.
@freecourseplatformenglish2829
@freecourseplatformenglish2829 Месяц назад
May be not, he probably have received Guru Purnima wishes last year also.
Далее
Design LeetCode - System Design Interview
12:11
Просмотров 2,4 тыс.
Sort an Array - Leetcode 912 - Python
17:13
Просмотров 37 тыс.
Please Master These 10 Python Functions…
22:17
Просмотров 149 тыс.
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
WHY did this C++ code FAIL?
38:10
Просмотров 256 тыс.
10 Math Concepts for Programmers
9:32
Просмотров 1,9 млн
Fast Inverse Square Root - A Quake III Algorithm
20:08
3 Types of Algorithms Every Programmer Needs to Know
13:12