CT022

Arithmetic Ancestor Tree

EasyAcceptance: 0.0%

The Codetikki elders encode arithmetic expressions as binary trees: each leaf is an integer, and each internal node is one of +, -, *, or /. Given the root of such a tree, evaluate it. Input: a binary tree in level-order, with operators as single characters (+, -, *, /) and leaves as integers. Use "null" for absent nodes. Output: the integer result of evaluating the expression (use integer division for /).

Example 1:

Input: * + - 3 2 4 5
Output: 45

Example 2:

Input: + 2 3
Output: 5

Constraints:

1 <= number of nodes <= 10^4 Leaf values are integers in [-10^4, 10^4] Division always yields an integer result

Tags:

trees recursion dfs
Loading...
Test Cases:No test cases
No test cases available.
Coding Problem Not Found | CodeTikki