
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Find three element from different three arrays such that that a + b + c = sum in Python
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
Example
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))
Input
[2,3,4,5,6], [3,4,7,2,3], [4,3,5,6,7], 12
Output
True
- Related Articles
- Maximum sum from three arrays such that picking elements consecutively from same is not allowed in C++
- Find sub-arrays from given two arrays such that they have equal sum in Python
- Maximum subsequence sum such that no three are consecutive in C++ Program
- Maximum subsequence sum such that no three are consecutive
- 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++
- Plus One in Python
- Find longest bitonic sequence such that increasing and decreasing parts are from two different arrays in Python
- Find longest bitonic sequence such that increasing and decreasing parts are from two different arrays in C++
- Remove Edges Connected to a Node Such That The Three Given Nodes are in Different Trees Using C++
- Find a triplet such that sum of two equals to third element in C++
- Minimize (max(A[i], B[j], C[k]) – min(A[i], B[j], C[k])) of three different sorted arrays in Python
- Find pairs with given sum such that pair elements lie in different BSTs in Python
- Plus One Linked List in C++
- Cplus plus vs Java vs Python?

Advertisements