- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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

return True

return False

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

True

- Related Questions & Answers
- Maximum sum from three arrays such that picking elements consecutively from same is not allowed in C++
- Maximum subsequence sum such that no three are consecutive
- Maximum subsequence sum such that no three are consecutive in C++ Program
- Find minimum sum such that one of every three consecutive elements is taken in C++
- Find three closest elements from given three sorted arrays in C++
- Find sub-arrays from given two arrays such that they have equal sum in Python
- Find all pairs (a, b) in an array such that a % b = k in C++
- Find longest bitonic sequence such that increasing and decreasing parts are from two different arrays in Python
- Minimize (max(A[i], B[j], C[k]) – min(A[i], B[j], C[k])) of three different sorted arrays in Python
- Find largest d in array such that a + b + c = d in C++
- Find longest bitonic sequence such that increasing and decreasing parts are from two different arrays in C++
- Find a triplet such that sum of two equals to third element in C++
- Find three integers less than or equal to N such that their LCM is maximum - C++
- Find three integers less than or equal to N such that their LCM is maximum in C++
- Find a palindromic string B such that given String A is a subsequence of B in C++

Advertisements