DIY: Basic Calculator II
Solve the interview question "Basic Calculator II" in this lesson.
We'll cover the following
Problem statement
In this challenge, you are given a string, st
, which contains an expression. You’ll evaluate this expression and return its value. Keep the following statements in mind while solving the problem:
- The integer division should be rounded off to the nearest smallest integer.
- The given expression is always valid, giving the intermediate result in the range of -, - .
- You are not allowed to use any built-in function that evaluates the string as a mathematical expression.
Constraints:
st
will contain an expression made up of integers and operators (*
,/
,+
,-
) and separated by some number of spaces.- The expression will contain non-negative integers in the range , - .
-
st.length
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.