Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Maximum in BST

EasyPython00:00
I
Practice interviewer
In session
5 left
00:00

Your question is Find Maximum in BST. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

In a Publicis Sapient interview setting, implement a function that returns the maximum value stored in a binary search tree (BST). Use the BST property to solve the problem efficiently instead of scanning every node.

A BST is defined such that for every node, values in the left subtree are smaller and values in the right subtree are larger. Because of this property, the maximum value is always found at the rightmost node.

Formal Specification

  • Input: root, the root node of a binary search tree, or None for an empty tree
  • Output: The maximum integer value in the tree, or None if the tree is empty

Constraints

  • 0 <= number of nodes <= 10^5
  • -10^9 <= Node.val <= 10^9
  • The tree satisfies binary search tree ordering rules
  • Return None if root is null

Function Signature

def find_max_bst(root):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output