FastPrepEvaluate Indexed Arithmetic Equations

Evaluate Indexed Arithmetic Equations

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

The four arrays are aligned. At index i, apply operator +, -, *, or / to left[i] and right[i], and report whether the exact mathematical result equals expected[i].

Division by zero is false. Division is true only when the quotient is an integer equal to expected.

Function

evaluateEquations(left: int[], right: int[], expected: int[], operators: String[]) → boolean[]

Examples

Example 1

left = [2,5,3,8]right = [3,2,4,2]expected = [5,3,12,4]operators = ["+","-","*","/"]return = [true,true,true,true]

Each supported operation evaluates true.

Example 2

left = [1,2]right = [1,2]expected = [3,5]operators = ["+","*"]return = [false,false]

Incorrect expected values return false.

Constraints

  • 0 <= left.length <= 100000
  • All arrays have equal length; integer values are in [-10000,10000].

More ZipRecruiter problems

See ZipRecruiter hiring insights
public boolean[] evaluateEquations(int[] left, int[] right, int[] expected, String[] operators) {
    // Write your code here.
}
left[2,5,3,8]
right[3,2,4,2]
expected[5,3,12,4]
operators["+","-","*","/"]
expected[true,true,true,true]
Checking account…