Amdocs Coding Questions Solved | Question 2 | Codewindow.in

Question :

In this task you are requested to find if the sum of two numbers in a given array equals to a given sum. If such numbers exist you should return them as a tuple, if not, you should return -1.

Example:
[1,3,6,8,9]
And the following sum is: 17
The function should return: (8,9) (9,8)

Solution :

Python

#https://codewindow.in
#join our Telegram @codewindow


x=list(map(int,input().split(',')))
Sum=int(input())

r=[]
for i in x:
    for j in x:
        if i!=j:
            #print(i,j)
            if i+j==Sum:
                if i>j:
                    i,j=j,i
                
                s=(i,j)
                if s not in r:
                    r.append(s)
t=""
for i in r:
    t+=str(i)+","


for i in range(0,len(t)-1):
    if t[i] != " ":
        print(t[i],end="")


#end

Follow us

Also Checkout

Leave a Comment

Your email address will not be published. Required fields are marked *