Update appNew update is available. Click here to update.
About
My Stats
EXP gained
yellow-spark
3392
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
2
Know more
52
Total problems solved
37
Easy
15
Moderate
0
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

4 days

Less

More

Achievements
1
Ronin
Topics
Linked List
Discussions
why are two testcases failing in java?
Interview problems

code here:

 

public static int diameterOfBinaryTree(TreeNode<Integer> root) {

        // Write your code here.

        int[] maximum = new int[1];

        maximum[0] = -1;

        getDiameter(root, maximum);

        return maximum[0];

   

    }

    public static int getDiameter(TreeNode<Integer> root, int[] maximum) {

        if(root == null)

        return 0;

        int lh = getDiameter(root.left, maximum);

        int rh = getDiameter(root.right, maximum);

        //max[0] = Math.max(max[0], 1 + lh + rh);

        maximum[0] = Math.max(maximum[0], (lh+rh)) ;

        return 1 + Math.max(lh, rh);

    }

profile
YASH AGARWAL
Published On 05-Oct-2023
73 views
0 replies
0 upvotes