Max Sum Path in Binary Tree

  Рет қаралды 6,252

Code with Alisha

Code with Alisha

Күн бұрын

Пікірлер: 21
@smanivesh
@smanivesh 2 жыл бұрын
This is the BEST explanation for this question on you tube.❤
@fine2981
@fine2981 Жыл бұрын
Wow thank you so much ....best explanation available on you tube for this question.
@saishanmukh3805
@saishanmukh3805 2 ай бұрын
This is such a neat explanation!
@antojoshwa966
@antojoshwa966 3 жыл бұрын
Great explanation . Deserve more subs
@TarunKumar-cn6in
@TarunKumar-cn6in Жыл бұрын
Best explanation 👍
@mohakbansal5866
@mohakbansal5866 2 жыл бұрын
best solution keep making more videos
@hardcash9930
@hardcash9930 Жыл бұрын
hi just loved the starting part where you said we are going to do a problem ans rhyming just made my day
@abhitejamandava1619
@abhitejamandava1619 Жыл бұрын
Excellent explanation
@NM-on2zt
@NM-on2zt Жыл бұрын
Crisp explanation 👏👏
@KS0607
@KS0607 Жыл бұрын
crystal clear ...thanks ...short and crisp...
@neerajmahapatra5239
@neerajmahapatra5239 2 жыл бұрын
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?
@soumyaranjansahoo2836
@soumyaranjansahoo2836 2 жыл бұрын
mam your explanation is always best
@SumitKumar-ne9kc
@SumitKumar-ne9kc Жыл бұрын
thanks ,
@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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
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*
Maximum path sum from any node
14:24
Code with Alisha
Рет қаралды 3,5 М.
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 147 МЛН
Binary Tree Maximum Path Sum (Animated Walkthrough) (LeetCode)
11:43
AlgosWithMichael
Рет қаралды 23 М.
L17. Maximum Path Sum in Binary Tree | C++ | Java
17:50
take U forward
Рет қаралды 363 М.
49 Maximum Path Sum | From any node to any node
12:16
Aditya Verma
Рет қаралды 116 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Binary tree maximum path sum | Leetcode #124
15:23
Techdose
Рет қаралды 55 М.
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 147 МЛН