Other Test:
1.Count the number of pairs in integer array whose sum equals given sum (all elements are unique).
n = int(input())
s = int(input())
l = input()
l=l.split(" ")
su = 0
for i in range(len(l)-1):
for j in range(i+1,len(l)):
if(int(l[i])+int(l[j])==n):
su=su+1
print(su)
2.Write a program to get an integer array find the second largest element (where array has only distinct elements)
n=int(input())
l=input()
l=l.split(" ")
n=[]
for i in l:
n.append(int(i))
n=sorted(n)
print(n[len(n)-2])
No comments:
Post a Comment