'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();

Array Practice Test

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