Suppose we have three arrays A, B, C and another value called "sum", We have to check whether there are three elements a, b, c such that a + b + c = sum and a, b and c should be under three different arrays.
So, if the input is like A = [2,3,4,5,6], B = [3,4,7,2,3], C = [4,3,5,6,7], sum = 12, then the output will be True as 4+2+6 = 12, and 4, 2, 6 are taken from A, B, C respectively.
To solve this, we will follow these steps −
for i in range 0 to size of A, do
for j in range 0 to size of B, do
for k in range 0 to size of C, do
if A[i] + B[j] + C[k] is same as sum, then
Let us see the following implementation to get better understanding −
def is_sum_from_three_arr(A, B, C, sum): for i in range(0 , len(A)): for j in range(0 , len(B)): for k in range(0 , len(C)): if (A[i] + B[j] + C[k] == sum): return True return False A = [2,3,4,5,6] B = [3,4,7,2,3] C = [4,3,5,6,7] sum = 12 print(is_sum_from_three_arr(A, B, C, sum))
[2,3,4,5,6], [3,4,7,2,3], [4,3,5,6,7], 12