Evaluate Sequential Variable Assignments
Problem statement
Process assignments in order. Assignment i evaluates expressions[i] using the current variable values, then stores the result in the variable names[i]. Return the value produced by each assignment.
An expression contains nonnegative decimal integer literals, lowercase variable names, optional unary + or - before an operand, and binary +, -, *, and /. Spaces may appear between tokens. Parentheses are absent.
Examples
Example 1
names = ["a","b","c"]expressions = ["2 + 3 * 4","a / 3","b * -2 + a"]return = [14,4,6]a is 14, b is 14 / 3 = 4, and c is 4 * -2 + 14 = 6.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.