Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a Binary Tree, find maximum and minimum elements in it.

**Example 1:**

Input:Output:11 1Explanation:The maximum and minimum element in this binary tree is 11 and 1 respectively.

**Example 2:**

Input:6 / \ 5 8 / 2Output:8 2

**Your Task:**

You don't need to read input or print anything. Your task is to complete **findMax() **and **findMin() **functions which take root node of the tree as input parameter and return the maximum and minimum elements in the binary tree respectively.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 <= Number of nodes <= 10^{5}

1 <= Data of a node <= 10^{5}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Max and min element in Binary Tree

...