3
int[] ans = new int[1];5
public int maxPathSum(TreeNode root) {6
ans[0] = root.val; // Handle edge case11
public int dfs(TreeNode root) {13
if (root == null) return 0;16
Math.max(0, dfs(root.left)); // Check on the left subtree and if returned negative take 018
Math.max(0, dfs(root.right)); // Check on the right subtree and if returned negative take 022
+ right; // Calculating the max while including the root its left and right child.23
ans[0] = Math.max(ans[0], maxInTheNode); // Keeping max globally28
right); // Since only one split is allowed returning the one split that returns max