DIY: Basic Calculator

Solve the interview question "Basic Calculator" in this lesson.

Problem statement

In this challenge, you have to implement a very basic calculator that evaluates a simple expression string. The calculator should handle the + and - operators and the () parentheses. The expression string can contain integer numeric values and empty spaces (which will be ignored).

Input

The input will be a string representing the mathematical expression. For example:

((2 - 1) + (7 - 3))

Output

The output will be an integer value obtained by evaluating the expression string. The following is an example output:

5

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.