FastPrepCheck Array Arithmetic Expressions

Check Array Arithmetic Expressions

Capital One logoCapital One● EasyFULLTIMEOA
Learn

Problem statement

You are given three equal-length integer arrays a, b, and c, together with an equal-length character array signs.

Each element of signs is either '+' or '-'. Return a boolean array result of the same length, where result[i] is true exactly when applying signs[i] to a[i] and b[i] produces c[i].

  • If signs[i] == '+', check whether a[i] + b[i] == c[i].
  • If signs[i] == '-', check whether a[i] - b[i] == c[i].

Function

checkArithmeticExpressions(a: int[], signs: char[], 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 checks are 3 + 2 = 5, 2 - 7 != 5, -1 - (-5) = 4, and 4 + 2 != 2.

Constraints

  • 1 <= a.length == b.length == c.length == signs.length <= 10^5
  • -10^9 <= a[i], b[i], c[i] <= 10^9
  • Every value in signs is either '+' or '-'.
  • Every evaluated addition or subtraction fits a signed 32-bit integer.

Source note: Source screenshot from a reported Capital One online assessment.

More Capital One problems

See Capital One hiring insights
public boolean[] checkArithmeticExpressions(int[] a, char[] 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…