Instagram
youtube
Facebook
Twitter

Python pattern with integers Codechef solution

Problem:

If we have 3 positive integers, show if any one of them can be written as the sum of the other 2 integers.

Input:

First line will contain the number 5, which is the number of testcases. Then the testcases follow.
Each testcase contains a single line of input, with three space-separated positive integers x, y, z

Output:

For each testcase, output in a single line, "YES" if it's possible to represent any integer among the three integers as the sum of the other two integers, and "NO" if not.

NOTE: The output is case insensitive, meaning both uppercase and lowercase characters can be used at any position of the output string.

Constraints

1<=x,y,z<=1000

Sample Input:

5 
1 1 2 
1 3 2 
2 2 2 
100 100 201 
11 22 33

Sample Output:

YES 
YES 
NO 
NO 
YES

Explanation:

Case 1: For this case, the third integer can be written as the sum of the first two. 
2=1+1

Case 2: For this case, the second integer can be written as the sum of the first and third. 
3=1+2

Case 3: For this case, no integer can be written as the sum of other two.

Case 4: For this case, no integer can be written as the sum of other two.

Case 5: For this case, the third integer can be written as the sum of the first two. 
33=11+22

Solution:

n=int(input(“Enter the number of terms: “))
for i in range(n):
    a,b,c=map(int,input(“Enter 3 numbers: “).split())
    if a+b==c or a+c==b or b+c==a:
        print("YES")
    else: print("NO")

Steps to solve this problem:

  • Take input from the user and store it in variable n

  • Follow next steps under for loop

  • Using map function get the iterators and store them in variables a, b, c

  • Now check if the sum of two values returns the third value print “Yes” else return “No”