01Phone Screenwith Software EngineerTechnical45 minMedium
Interviewer: Software Engineer
Was asked to solve the following binary tree question
Problem Statement:
Given a binary tree where each node contains either an operator (+, -, *, /) or an integer. The tree represents a mathematical expression where each leaf node is an integer and each internal node is an operator that combines the values of its left and right subtrees. Evaluate the expression represented by the binary tree to return an integer value.
Example:
Input:
*
/ \
+ 5
/ \
3 2
Output: 25
Input:
-
/ \
* 4
/ \
6 3
Output: 14