Menu Close

Replace every element with the greatest element on right side…-FTC

Write a program to replace every element with the greatest element on right side

A = list(map(int,input("Enter the numbers: ").split())) 
#map returns the object.It passes elements from 2nd arguement to 1st.

N=len(A)

for i in range(N):
	temp=A[i]
	for j in range(i,N):
		if A[j]>temp:
			A[i]=A[j]
			break

print(A)



'''
Input:
	Enter the numbers: 16 17 4 3 5 2
Output:
    [17, 17, 5, 5, 5, 2]
'''

Leave a Reply

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