FastPrepMaximum Value in a Binary Tree

Maximum Value in a Binary Tree

Akuna Capital logoAkuna Capital● EasyNEW GRADPHONE SCREEN
Learn

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

See Akuna Capital hiring insights
public int findMaximumValue(TreeNode root) {
    // write your code here
}
root[3,1,5,null,2,4,8]
expected8
Checking account…