Check Array Arithmetic Expressions
Problem statement
You are given integer arrays a, b, and c, and a string array signs. All four arrays have the same length. Each entry of signs is "+" or "-".
For each index i, apply signs[i] to a[i] and b[i]. Return a boolean array whose entry at i is true if that result equals c[i], and false otherwise. Keep the same index order.
For this exercise, assume empty arrays are allowed; their result is an empty array.
Function
checkExpressions(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 equations are checked separately:
3 +2 =5, so the first result istrue.2 -7 =-5, which differs from5, so the second isfalse.-1 -(-5) =4, so the third istrue.4 +2 =6, which differs from2, so the fourth isfalse.
Example 2
a = [-5,0]signs = ["-","+"]b = [-2,0]c = [-3,0]return = [true,true]-5 -(-2) =-3 and 0 +0 =0. Both equations are true.
Example 3
a = []signs = []b = []c = []return = []There are no indices to check, so the result is an empty array.
Constraints
- For this exercise, assume
0 <= a.length <=1000. a,signs,b, andchave the same length.- Each entry of
signsis"+"or"-". - For this exercise, assume every value in
a,b, andcis between-10^9and10^9, inclusive.