Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a program to find the maximum element in a binary tree.

Hard

Problem Statement

Implement a program to find the maximum element in a binary tree.

Sample Input

A binary tree with values: 10, 5, 15, 3, 7, 13, 18.

Sample Output

Maximum value: 18

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <iostream> class TreeNode { public: int data; TreeNode *left; TreeNode *right; TreeNode(int val); }; class BinaryTree { private: TreeNode *root; public: BinaryTree(); void insert(int value); int getMax(); }; int main() { // Logic to demonstrate BinaryTree functionality return 0; }
Log in or sign up to run or submit your code.Log inSign up
Input
A binary tree with values: 10, 5, 15, 3, 7, 13, 18.
Expected Output
Maximum value: 18