Python Program to replace every element with the greatest element on right side

Description

Python Program to get list size n and n elements of list, replace every elements with the greatest element located in right side.
Input:
5
5 7 9 3 1
Output:
9 9 3 3 1

Solution

l=list(map(int,input("Enter numbers:").split(" ")))
for i in range(0,len(l)-1):
    max1=l[i+1]
    for j in range(i+2,len(l)):
        if(l[j]>max1):
            ind=j
            max1=l[j]
    l[i]=l[ind]

print(l)

We are Teaching "Web Development using Python" through Online.

View Tutor Profile and Course Syllabus

Explanation

visit each location in list

find the greatest element (max1)next to the location using

Store the max1 in current location by
l[i] = max1
Ramesh P Natarajan

Author - Ramesh P Natarajan

Software Developer and Technology Trainer, very much passionate in the field of Software Application Development, Machine Learning and Search Engine Optimization.

Write to: [email protected]





Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution