Foundations Conditions
587. Simple Calculator
You are given two integers a and b and an operator op, which is one of "+", "-", "*" and "/".
Return the result of a op b: the sum, the difference, the product or the quotient.
Division keeps only the whole part of the quotient and rounds toward zero. So 7 / 2 is 3, and −7 / 2 is −3, not −4.
The answer can be larger than 253, so the JavaScript starter returns a BigInt.
Example 1
Input: a = -17, b = 5, op = "/"
-3Explanation: −17 / 5 is −3.4. Keeping the whole part gives −3. Rounding down would give −4, which is not the answer.
Example 2
Input: a = 15, b = -4, op = "-"
19Explanation: Subtracting −4 is the same as adding 4, so 15 − (−4) = 19.
Example 3
Input: a = 1000000000, b = -999999999, op = "*"
-999999999000000000Check your understanding
Work out the answer for this input before you write any code.
Constraints
-109 ≤ a, b ≤ 109opis one of"+","-","*"and"/".bis not 0 whenopis"/".
Clarifying questions
What you would ask an interviewer before writing any code.