Distribute Coins in Binary Tree - Leetcode 979 - Python

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
    🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
    🐦 Twitter: / neetcode1
    ⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
    Problem Link: leetcode.com/problems/distrib...
    0:00 - Read the problem
    0:15 - Drawing Explanation
    12:06 - Coding Explanation
    leetcode 979
    #neetcode #leetcode #python

Komentáře • 27

  • @tommyshelby6277
    @tommyshelby6277 Před 2 měsíci +34

    bro sneaked in `ladoos` and thought we wouldn't notice😂?

  • @arihantsinghrana2173
    @arihantsinghrana2173 Před 2 měsíci +18

    Thank you soo much for making these video and soo early as well!!!

  • @weens571
    @weens571 Před 2 měsíci +4

    Just when I needed the video. Thanks. 😁

  • @aashishbathe
    @aashishbathe Před 2 měsíci +7

    LADDOOO AGAINNN. Just remembering that, I just had it yesterday and it was great!

  • @user-he4st2ro5h
    @user-he4st2ro5h Před 2 měsíci +4

    Actually, the second solution with one variable is much easier to understand imho.

  • @MP-ny3ep
    @MP-ny3ep Před 2 měsíci

    Great explanation as always. Thank you

  • @chien-yuyeh9386
    @chien-yuyeh9386 Před 2 měsíci

    Thanks for sharing 🎉

  • @shashwatsingh9247
    @shashwatsingh9247 Před 2 měsíci

    Tough ques. thanks neetcode

  • @HimanshuSaini-ur6by
    @HimanshuSaini-ur6by Před 2 měsíci

    This was great..by 9 minute mark I got an idea and coded it out. it workedd

  • @vedantjha2327
    @vedantjha2327 Před 2 měsíci

    Interesting question.

  • @pastori2672
    @pastori2672 Před 2 měsíci +1

    i actually struggled so much on this one and i thought your gonna clown them for the difficulty again but i guess not

  • @kwakukusi4094
    @kwakukusi4094 Před 2 měsíci

    best explanation

  • @sivaramakrishnankn1721
    @sivaramakrishnankn1721 Před 2 měsíci +3

    boondhi laddoo gang represent

  • @shivangikhemka4379
    @shivangikhemka4379 Před 2 měsíci

    Hey, How would be solve this to get minimum number of moves if we had more total coins than number of total nodes?
    total coins > total nodes
    (Extended problem)

  • @kevinwang8632
    @kevinwang8632 Před 2 měsíci +1

    this one was hard

  • @nikitathacker5096
    @nikitathacker5096 Před měsícem

    How can we conclude that this question doesnt require DP? At first glance, we have choices and we need minimum, making it a good candidate for DP

  • @priyanshagarwal8490
    @priyanshagarwal8490 Před 2 měsíci

    2055. Plates Between Candles... Next Please..🙏

  • @staywithmeforever
    @staywithmeforever Před 2 měsíci

    Double bfs?

  • @sajankumarrajbanshi1158
    @sajankumarrajbanshi1158 Před 2 měsíci

    i love ladoos

  • @impolitebigmac3044
    @impolitebigmac3044 Před 2 měsíci +36

    I hate leetcode

  • @Masterasadumar
    @Masterasadumar Před 2 měsíci +2

    lol ladu

  • @vijayanks1714
    @vijayanks1714 Před 2 měsíci

    public int[] dfs(TreeNode root){
    if(root == null) return new int[]{0,0}; //size, coins
    int[] left = dfs(root.left);
    int[] right = dfs(root.right);
    int[] curr = new int[]{left[0]+right[0]+1, left[1]+right[1]+root.val};
    res += Math.abs(curr[0] - curr[1]);
    return curr;
    }
    java code

  • @sankhadip_roy
    @sankhadip_roy Před 2 měsíci

    extra = left_extra+right_extra+1-node.val # calculated it from the first solution equations
    extra = left_extra+right_extra-1+node.val # provided by neetcode
    both is working don't know how