FastPrepMaximum Value in a Binary Tree
Problem · Tree

Maximum Value in a Binary Tree

Learn this problem
EasyAkuna Capital logoAkuna CapitalNEW GRADPHONE SCREEN

Problem statement

Given the root of a nonempty binary tree, return the maximum value stored in any node.

Your implementation must handle trees whose values are all negative.

Function

findMaximumValue(root: TreeNode) → int

Examples

Example 1

root = [3,1,5,null,2,4,8]return = 8

The largest node value is 8.

Example 2

root = [-8,-12,-3]return = -3

All values are negative, so the least negative value is the maximum.

Constraints

  • The tree contains from 1 through 10^5 nodes.
  • -10^9 <= Node.val <= 10^9.

More Akuna Capital problems

drafts saved locally
public int findMaximumValue(TreeNode root) {
    // write your code here
}
root[3,1,5,null,2,4,8]
expected8
checking account