Computer Science, asked by niharikamanam, 3 months ago

You are given an array A containing N elements. You do the following step repeatedly:
• Take any 2 elements and add the sum of their absolute difference back to the array.
Calculate the number of distinct possible values the array contains after an infinite number of steps modulo 10^9+7.

Input format:
• The first line contains an integer N denoting the number of elements in A.
•Each line i of N subsequent lines(where 0<=i Constraints:
1<=N<=10^5
1<=A[i]<=10^9

Answers

Answered by pkumarbabal
13

Answer:

def getPossible(A):

dict={}

B=[]

for i in A:

 dict[i]=1

A.sort()

for i in range(len(A)):

 if dict.get(A[i])==None:  

  dict[A[i]]=1

for i in range(len(A)):

 for j in range(i+1,len(A)):

  if A[j]!=A[i]:

   rus=A[j]-A[i]

   if dict.get(rus)==None:

    dict[rus]=1

    B.append(rus)  

while(len(B)!=0):

 c=B.pop(0)

 for i in range(len(A)):

  rus=abs(c-A[i])

  if dict.get(rus)==None:

   dict[rus]=1

   B.append(rus)

   

 A.append(c)

return len(dict.keys())

     

def main():

   N = int(input())

   A=[None]*N

   for j in range(N):

       A[j] = int(input())

   

   result = getPossible(A);

   print(result)

if __name__ == "__main__":

   main()

Explanation:

Please check my all sample test cases and  3 hidden test cases were correct in infosys sample test. Its not totally correct but if you find any corrections and can also help me please tell me.

Answered by jaybhvani5637
0

Answer:

9×a By Square 1<=10hjjreld

Similar questions