Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to evaluate a mathematical expression string (e.g., "3 + 2 * (4 - 1)").

Hard

Problem Statement

Write a function to evaluate a mathematical expression string (e.g., "3 + 2 * (4 - 1)").

Sample Input

"3 + 2 * (4 - 1)"

Sample Output

9

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Evaluate a mathematical expression from a string function evaluateExpression(expr) { // Use Function constructor to evaluate the string as code } console.log(evaluateExpression("3 + 2 * (4 - 1)"));
Log in or sign up to run or submit your code.Log inSign up
Input
"3 + 2 * (4 - 1)"
Expected Output
9