Replace Elements with Greatest Element on Right Side Problem
Replace Elements with Greatest Element on Right Side Problem — ExecCode Easy DSA Practice
Solve the Replace Elements with Greatest Element on Right Side problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. Your task is to after doing so, return the array.
Examples
Input {"arr": [17, 18, 5, 4, 6, 1]}; Output [18, 6, 6, 6, 1, -1]. Input {"arr": [400]}; Output [-1]
Constraints
1 <= arr.length <= 10^4 1 <= arr[i] <= 10^5
Practice Replace Elements with Greatest Element on Right Side free on ExecCode. Browse DSA problems, topic map, and placement guides.