Build a Matrix With Conditions - Leetcode 2392 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024

ความคิดเห็น • 51

  • @rahulsbhatt
    @rahulsbhatt 2 หลายเดือนก่อน +41

    Happy Guru Purnima @NeetCodeIO
    Thank you so much for everyting!

  • @harithak9459
    @harithak9459 2 หลายเดือนก่อน +24

    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 2 หลายเดือนก่อน

      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 2 หลายเดือนก่อน +1

      so proud of you bro

  • @freecourseplatformenglish2829
    @freecourseplatformenglish2829 2 หลายเดือนก่อน +4

    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 🎉

  • @anujyouthoob
    @anujyouthoob 2 หลายเดือนก่อน +3

    I'm on a 99 day daily challenge streak and Neetcode has played a big role in it

  • @gavinebenezer1670
    @gavinebenezer1670 2 หลายเดือนก่อน +48

    I’m cooked 💀

    • @vaxxnsh
      @vaxxnsh 2 หลายเดือนก่อน +13

      we're all cooked

    • @advaitdongre
      @advaitdongre 2 หลายเดือนก่อน +1

      Fr

  • @aadil4236
    @aadil4236 2 หลายเดือนก่อน +2

    Great Problem. I solved it after seeing Topological sort under Hints. Really good problem. You have taught me everything Navdeep. Thank you.

  • @selfhelpguy5589
    @selfhelpguy5589 2 หลายเดือนก่อน +2

    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 2 หลายเดือนก่อน +1

    I'm preparing for ICPC regional . I can't thank you enough man. You're a legend!

  • @SarweshParsewar
    @SarweshParsewar 2 หลายเดือนก่อน +1

    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🎉

  • @viveksoni3269
    @viveksoni3269 2 หลายเดือนก่อน

    The topological sort algo was a good one, I used to do it by maintaining an in-degree vector.

  • @yash-uy5ym
    @yash-uy5ym 2 หลายเดือนก่อน

    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❤

  • @NEO-wl9ox
    @NEO-wl9ox 2 หลายเดือนก่อน

    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

  • @ayanpatel_98
    @ayanpatel_98 2 หลายเดือนก่อน +2

    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  2 หลายเดือนก่อน

      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

  • @rameezalipacific
    @rameezalipacific 2 หลายเดือนก่อน

    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?

  • @pastori2672
    @pastori2672 2 หลายเดือนก่อน +1

    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

  • @satyamjha68
    @satyamjha68 2 หลายเดือนก่อน +2

    Solved it !

  • @ayushmandash948
    @ayushmandash948 2 หลายเดือนก่อน +1

    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  2 หลายเดือนก่อน +2

      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 2 หลายเดือนก่อน +1

      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 2 หลายเดือนก่อน

      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 2 หลายเดือนก่อน

      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 2 หลายเดือนก่อน +1

      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?

  • @manojvn2612
    @manojvn2612 2 หลายเดือนก่อน

    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  2 หลายเดือนก่อน +2

      Mainly because it felt similar to course schedule and alien dictionary. Not saying it's easy of course.

  • @codingmickey
    @codingmickey 2 หลายเดือนก่อน

    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  2 หลายเดือนก่อน

      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 2 หลายเดือนก่อน

      @@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 2 หลายเดือนก่อน

      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

  • @anandsahoo3711
    @anandsahoo3711 2 หลายเดือนก่อน

    dayum bro hell of a experience this question was

  • @emmanuelidoko1694
    @emmanuelidoko1694 2 หลายเดือนก่อน

    Really good stuff
    Thankyou so much Neetcode

  • @chien-yuyeh9386
    @chien-yuyeh9386 2 หลายเดือนก่อน +1

    Thanks for sharing 🎉

  • @GeetainSaar
    @GeetainSaar 2 หลายเดือนก่อน +1

    happy guru purnima.
    guru ji make app development adroid projects free

  • @anandsrikumar007
    @anandsrikumar007 2 หลายเดือนก่อน

    Thank you

  • @JamesBond-mq7pd
    @JamesBond-mq7pd 2 หลายเดือนก่อน +2

    it's even hard to copy!

  • @arihantsinghrana2173
    @arihantsinghrana2173 2 หลายเดือนก่อน +1

    Break means no more daily uploads ?

    • @NeetCodeIO
      @NeetCodeIO  2 หลายเดือนก่อน +13

      I'll be back for tomorrow

    • @arihantsinghrana2173
      @arihantsinghrana2173 2 หลายเดือนก่อน

      @@NeetCodeIO thank the lord 🙌🙌

    • @arihantsinghrana2173
      @arihantsinghrana2173 2 หลายเดือนก่อน +1

      And yeah happy Guru Purnima @NeetCodeIO 😁

  • @hithambasheir3283
    @hithambasheir3283 2 หลายเดือนก่อน

    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

  • @tuandino6990
    @tuandino6990 2 หลายเดือนก่อน

    Im so happy to solve this

  • @rostislav_engineer
    @rostislav_engineer 2 หลายเดือนก่อน

    thanks for this!

  • @AkeshKumar-h8g
    @AkeshKumar-h8g 2 หลายเดือนก่อน

    prefer khans algo for toposort

  • @iliadmitriev01
    @iliadmitriev01 2 หลายเดือนก่อน

    Since we all got things to do and places to be 😂😂😂😂

  • @abhilashpatel6852
    @abhilashpatel6852 2 หลายเดือนก่อน

    I bet you're confused why you suddenly being called guru today😂.