Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Basic Calculator



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Simple Expression Calculator

Simple Expression Calculator

Problem Statement

Create a simple calculator that can evaluate arithmetic expressions given as strings.

The expressions will only include non-negative integers and the operators +, -, *, /, along with optional spaces. Division should truncate results towards zero.

You can assume the input expression is always valid and no built-in evaluation functions should be used.

Examples

Example 1:
Input: "4+3*5"
Output: 19
Example 2:
Input: " 8 / 4 "
Output: 2
Example 3:
Input: " 10 + 6 / 3 "
Output: 12

Constraints

  • Expression length ranges from 1 to 250 characters.
  • Only non-negative integers less than 10000 are used.
  • Operators include +, -, *, / only.
  • Spaces can appear anywhere in the expression.