Binary Tree Cameras | Leetcode | DP on Trees

Поділитися
Вставка
  • Опубліковано 5 лис 2024

КОМЕНТАРІ • 72

  • @elijah9610
    @elijah9610 3 роки тому +21

    Dude, the intro is sooo funny 😂😂😂😂 I had to like it

  • @shashankgupta29
    @shashankgupta29 3 роки тому +10

    I would like to thank you so much for bringing up such nice intuitive approaches !!
    You are a true gem!
    I hope that I could press that like button multiple times !!

  • @abhinaysingh637
    @abhinaysingh637 2 роки тому +2

    Kaafi cool ban gye aap pehle ek min me😂

  • @hymnish_you
    @hymnish_you 3 роки тому +4

    Thankyou so much bro, I have used up a whole day to understand this. I have watched this video around 8 times coz I can't able to implement it due to the edge cases w/o referring to your code. Your content is no doubt exceptional, Thanks for that.
    if(root == null) {
    if(willPlace) return 1001;
    return 0;
    }

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +1

      You're welcome and thanks so much for the nice words :)
      Keep learning and coding.

  • @NamanBansal
    @NamanBansal 3 роки тому +17

    Loved the intro!

    • @tawfik1546
      @tawfik1546 3 роки тому +2

      yes , it got me hooked

  • @tathagatnegi5923
    @tathagatnegi5923 3 роки тому +2

    Thanks👍 one day every1 will came to know about the precious content of your channel ..

  • @tejasnakhate
    @tejasnakhate 3 роки тому

    Where were you all these time....spent so much time on this problem already

  • @shubheshtiwari8525
    @shubheshtiwari8525 3 роки тому

    bhiya ji to maze maze me samjha dete hain aur itni aasani se samjh bhi aa jata hai.cha gye bhiya ji.
    like and subscribe zaroor kro bhaiyon

  • @evolve.everydayy
    @evolve.everydayy 3 роки тому +2

    could you explain the last condition dp(u,0,0) for a general tree with more than 2 subtrees(the code)

  • @prajitbanerjee8226
    @prajitbanerjee8226 7 місяців тому

    Intro was legendary

  • @tharunchowdary14
    @tharunchowdary14 3 роки тому +2

    Mastering dp from this channel 🔥

  • @psurya3053
    @psurya3053 Рік тому

    thank you sir , i struggled a lot while solving, you made it easier .

  • @divanshmahajan1769
    @divanshmahajan1769 3 роки тому +1

    why are we considering a case where we allow the parent also and the grand parent of current node also to not have the camera ? we do this for both left and right child and suppose it gives min answer ..wont it be wrong?

  • @sujoyseal195
    @sujoyseal195 2 роки тому +1

    "Who can explain it better than Kartik Arora?🤣🤣🤣🤣" . I have not watched the full video yet , but my answer will be : Kartik Arora himself . Btw great job !

  • @sdeBack1
    @sdeBack1 3 роки тому +4

    15:03, dp( u , 0 , 0 ) than why need of Case 1 and Case2. ( we have to return inf ) As we can see if the current node and parent node have not camera then if we place the camera its child node then the child node can only monitor the current node, not the parent node( no one can monitor) .
    Anyone can tell me please ?

    • @soumyaporel6955
      @soumyaporel6955 3 роки тому

      Parent node is monitored by the camera in grandparent node i guess

  • @ujjwalmittal3785
    @ujjwalmittal3785 3 роки тому

    Time will be order of nlogn ig, only because of the cache ie dp array . We are using map here and not unordered map .
    We can't use unordered map .
    Also we can't take a 3d dp because the first parameter is a node and not an integer

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому

      Give a number to each node. unordered map node*, int.
      Then make 3d array for dp.

    • @ujjwalmittal3785
      @ujjwalmittal3785 3 роки тому +1

      @@AlgosWithKartik oh yes this idea is great .
      Thanks a lot sir .

  • @kSERITIKGupta
    @kSERITIKGupta 2 роки тому

    Sweet and Simple Explaination really loved it

  • @sahilkalamkar5332
    @sahilkalamkar5332 6 місяців тому

    Unable to understand why is there a need of keeping the monitoring state?

  • @gauravarora8405
    @gauravarora8405 5 місяців тому

    great explanation. i missed the case where parent can cover a child,, and so missed that state and couldn't figure out what was wrong..Also can you please explain the greedy solution and first explain why it works... That blew my mind

  • @parthpawar7837
    @parthpawar7837 3 роки тому +1

    I think whenever you upload a video, you should mention that somewhere on Codechef Discuss, atleast that's how I found this amazing channel, maybe more people come across your channel this way!

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +4

      Thanks Parth for the tip and the appreciation :)
      Will try to share the videos on relevant platforms.

  • @kunalpuri6935
    @kunalpuri6935 3 роки тому

    Nice tutorial, Kartik. Just one suggestion. I think the leaf case is not required to be handled. The base case (root == NULL) and the recursion itself handle that scenario. Thanks

  • @3darpan
    @3darpan 3 роки тому +1

    Can you explain your base case when root==NULL ?
    Why cant we always return 0?

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +2

      if node X is not monitored and X expects one of the child nodes to have a camera but turns out X has no child nodes. Let's say now I call solve(X->left).
      Then returning a 0 would be incorrect. I should return something that represents it is impossible to cover all the nodes now, given that X is not monitored.
      Let me know if this clears your doubt.

  • @GauravSingh-wi5pc
    @GauravSingh-wi5pc Рік тому

    if someone write bad about the features or anything , you will work on yourself ( no point of removing that comment )

  • @frogloki882
    @frogloki882 Рік тому

    This seems like a modified version of knapsack

  • @vishnuvardhan-md1ux
    @vishnuvardhan-md1ux 3 роки тому

    please explain line sweep and suffix arrays.

  • @bhuwaneshnainwal8323
    @bhuwaneshnainwal8323 2 роки тому

    God Of DP :)

  • @MayankKumar-nn6us
    @MayankKumar-nn6us 3 роки тому +1

    link is not opening

  • @jaishriharivishnu
    @jaishriharivishnu 4 місяці тому

    lol... in the starting of video, all of a sudden i lost my dizziness.

  • @skt7088
    @skt7088 3 роки тому

    great video sir,please make a video on how to make progress in codeforces contests,what to do if we are not able to solve div2c and div2d problems?

  • @bhamidipatisatwik1165
    @bhamidipatisatwik1165 3 роки тому

    Can we extend this solution to a k-ary tree from this binary tree approach?

  • @ujjvalsharma5055
    @ujjvalsharma5055 3 роки тому

    I completely encourage you to make more videos and work harder. You are doing a great job :), but I felt the problem could be explained a bit simpler. However, your videos are definity great and worth it!!

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому

      Thanks for the appreciation and the feedback :)

  • @tle964
    @tle964 3 роки тому +2

    Sir please switch on the camera for the whole video... it feels more connecting...hope you understand:)

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +1

      I do understand. I'll try to set it up properly so I can have the cam on for the entire video

    • @tle964
      @tle964 3 роки тому +1

      @@AlgosWithKartikyes sir..thank you🙂

  • @carry4398
    @carry4398 3 роки тому +1

    can we memoize using 3D vector ??? how we will store TreeNode's address in vector??

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому +1

      Yes we can.
      Give a number to each node of the tree.

    • @carry4398
      @carry4398 3 роки тому

      @@AlgosWithKartik oh, Got it! thanks :)

  • @shaswatadutta4451
    @shaswatadutta4451 3 роки тому

    Can it be done using BFS?

  • @yourbestie4138
    @yourbestie4138 3 роки тому +2

    super

  • @SuryaPrakash-pf9dr
    @SuryaPrakash-pf9dr 3 роки тому +1

    solution link is not working

    • @AlgosWithKartik
      @AlgosWithKartik  3 роки тому

      I think you need to be logged in to leetcode for accessing that link.
      adding ideone link in description instead.

    • @SuryaPrakash-pf9dr
      @SuryaPrakash-pf9dr 3 роки тому

      @@AlgosWithKartik logged in but not working btw i understand the solution thanks (y)

  • @youroverlord3886
    @youroverlord3886 3 роки тому

    can anyone explain line 34?

  • @tomorrowcut
    @tomorrowcut 3 роки тому

    Another great video.

  • @sujoyseal195
    @sujoyseal195 3 роки тому +1

    Great

  • @divyanshusingh9238
    @divyanshusingh9238 3 роки тому

    Great video 🔥

  • @Nikhil-ov6sm
    @Nikhil-ov6sm Рік тому

    happy to see how similar my code is to yours xD...

  • @ayushthakur2896
    @ayushthakur2896 2 роки тому

    Uniteresting problem xdddddddddddd