FastPrepCheck Array Arithmetic Expressions

Check Array Arithmetic Expressions

TikTok logoTikTok● EasyFULLTIMEOA
Learn

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 is true.
  • 2 -7 =-5, which differs from 5, so the second is false.
  • -1 -(-5) =4, so the third is true.
  • 4 +2 =6, which differs from 2, so the fourth is false.

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, and c have the same length.
  • Each entry of signs is "+" or "-".
  • For this exercise, assume every value in a, b, and c is between -10^9 and 10^9, inclusive.

More TikTok problems

See TikTok hiring insights
Saved
class Solution {
    public boolean[] checkExpressions(int[] a, String[] signs, int[] b, int[] c) {
        // Return one decision for each index.
        return new boolean[a.length];
    }
}
a[3,2,-1,4]
signs["+","-","-","+"]
b[2,7,-5,2]
c[5,5,4,2]
expected[true,false,true,false]
Checking account…