Write a program to find next greatest number in an array| Python

 

Write a program to find next greatest number in  an array| Python








TestCase1:
arr=[1,2,3,4]

Output:
[2,3,4,-1]

TestCase2:
arr=[100,2,4,6,63]

output:
[-1,4,6,63,-1]




"""
Aim:Write a Program to find Next greates integer in a array
"""

arr=[100,24,24,1,5]
max_arr,lst=[],[]
for i in range(0,len(arr)):
    j=arr[i]
    if(i==(len(arr)-1)):
        lst.append(-1)
        break
    else:
        for k in range(i+1,len(arr)):
            if(j<arr[k]):
                max_arr.append(arr[k])
            else:
                max_arr.append(-1)
    lst.append(min(max_arr))
    max_arr=[]
print(lst)


































Easy steps to understand the above problem.
Write a program to find next greatest number in an array| Python Write a program to find next greatest number in  an array| Python Reviewed by Shubham Prajapati on December 14, 2023 Rating: 5

No comments:

If you have any doubt so you can comment me then i will 100% help you ,Through comment Chat

Powered by Blogger.