Medium · System Design

Expression Tree / Design an Expression Tree

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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More System Design problems