FastPrepCheck Array Arithmetic Expressions

Check Array Arithmetic Expressions

Hudson River Trading logoHudson River Trading● EasyFULLTIMEOA
Learn

Problem statement

You are given equal-length integer arrays a, b, and c, and an equal-length array signs. Each sign is "+" or "-".

Return a boolean array whose value at index i is true exactly when applying signs[i] to a[i] and b[i] produces c[i]. For addition, check a[i] + b[i] == c[i]; for subtraction, check a[i] - b[i] == c[i].

Function

checkArithmeticExpressions(a: int[], signs: String[], b: int[], c: int[]) → boolean[]

Examples

Example 1

a = [3,2,-1,4]signs = ["+","-","-","+"]b = [2,7,-5,2]c = [5,5,4,2]return = [true,false,true,false]

The four calculations are 3 + 2 = 5, 2 - 7 = -5, -1 - (-5) = 4, and 4 + 2 = 6. Only the first and third equal their corresponding entries in c.

Example 2

a = []signs = []b = []c = []return = []

No expressions need checking, so the result is empty.

Constraints

  • 0 <= a.length == signs.length == b.length == c.length <= 1000
  • -1000 <= a[i], b[i], c[i] <= 1000
  • Each entry of signs is "+" or "-".

More Hudson River Trading problems

See Hudson River Trading hiring insights
public boolean[] checkArithmeticExpressions(int[] a, String[] signs, int[] b, int[] c) {
    // Write your code here.
}
a[3,2,-1,4]
signs["+","-","-","+"]
b[2,7,-5,2]
c[5,5,4,2]
expected[true,false,true,false]
Checking account…