Medium · System Design

Design an Expression Tree With Evaluate Function

Given a valid postfix expression as a list of tokens (non-negative integers and the operators +, -, *, /), build the corresponding binary expression tree and return the integer its root's evaluate() returns, where / truncates toward zero.

Examples

Example 1

{
  "postfix": ["3", "4", "+", "2", "*"]
}

Output: 14

Example 2

{
  "postfix": ["10", "2", "/", "3", "+"]
}

Output: 8

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More System Design problems