Max Sum Path in Binary Tree

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

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

  • @smanivesh
    @smanivesh 2 ปีที่แล้ว +5

    This is the BEST explanation for this question on you tube.❤

  • @fine2981
    @fine2981 ปีที่แล้ว +2

    Wow thank you so much ....best explanation available on you tube for this question.

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

    This is such a neat explanation!

  • @neerajmahapatra5239
    @neerajmahapatra5239 2 ปีที่แล้ว +3

    Amazing explanation..
    When I saw your video I checked my playback speed it was normal but I was feeling like it's in 1.5x is it you normal speed of saying?

  • @hardcash9930
    @hardcash9930 ปีที่แล้ว

    hi
    just loved the starting part where you said we are going to do a problem ans rhyming just made my day

  • @mohakbansal5866
    @mohakbansal5866 2 ปีที่แล้ว

    best solution keep making more videos

  • @TarunKumar-cn6in
    @TarunKumar-cn6in ปีที่แล้ว +1

    Best explanation 👍

  • @abhitejamandava1619
    @abhitejamandava1619 ปีที่แล้ว

    Excellent explanation

  • @antojoshwa966
    @antojoshwa966 3 ปีที่แล้ว +2

    Great explanation . Deserve more subs

  • @NM-on2zt
    @NM-on2zt ปีที่แล้ว

    Crisp explanation 👏👏

  • @SumitKumar-ne9kc
    @SumitKumar-ne9kc ปีที่แล้ว

    thanks ,

  • @soumyaranjansahoo2836
    @soumyaranjansahoo2836 2 ปีที่แล้ว

    mam your explanation is always best

  • @KS0607
    @KS0607 ปีที่แล้ว

    crystal clear ...thanks ...short and crisp...

  • @vijayakumareyunni6010
    @vijayakumareyunni6010 ปีที่แล้ว

    Good attempt. But I could not understand what constitutes a "path." I watched many videos, except one or two, and none explained the problem and "solution" clearly.

  • @sujalgupta6100
    @sujalgupta6100 ปีที่แล้ว +2

    Alisha, in these tree questions, I am not able to think recursively and facing difficulty. I always get a wrong answer. What to do ?

  • @sssumeet
    @sssumeet 2 ปีที่แล้ว

    Great Explanation. Please do provide Java Code solution if possible.

    • @anmolgupta6762
      @anmolgupta6762 ปีที่แล้ว +1

      I try avoiding global variables so I used an array of single element instead, you can also use global variable
      class Solution {
      public int solve(TreeNode root, int[] ans){
      if(root == null) return 0;
      int left = solve(root.left,ans);
      int right = solve(root.right,ans);
      int st_path = Math.max(root.val,Math.max((root.val + left),(root.val + right)));
      int cur_path = root.val + left + right;
      ans[0] = Math.max(ans[0],Math.max(st_path,cur_path));
      return st_path;
      }
      public int maxPathSum(TreeNode root) {
      int[] ans = new int[1];
      ans[0] = Integer.MIN_VALUE;
      solve(root,ans);
      return ans[0];
      }
      }
      This is the leetcode java code for problem : 124. Binary Tree Maximum Path Sum

  • @GhostRider....
    @GhostRider.... 2 ปีที่แล้ว

    public class Solution {
    int Solve(TreeNode A, int ans){
    if(A == null) return 0;
    int left = Solve(A.left, ans);
    int right = Solve(A.right, ans);
    int straight = Math.max(A.val, Math.max(left + A.val, right + A.val));
    int curved = A.val + left + right;
    ans = Math.max(ans, Math.max(straight, curved));
    return straight;

    }
    public int maxPathSum(TreeNode A) {
    int ans = Integer.MIN_VALUE;
    Solve(A, ans);
    return ans;
    }
    }
    Mam Can you tell error in this? It is giving error?

    • @anmolgupta6762
      @anmolgupta6762 ปีที่แล้ว +1

      Either make the ans variable global or use an array of size 1 to store ans if you want to solve like this. You cannot do like this in Java

  • @bharathkumar5870
    @bharathkumar5870 3 ปีที่แล้ว

    You solved this problem in your previous videos

  • @lalalajpat8602
    @lalalajpat8602 ปีที่แล้ว

    Gr*