Practice Replace Elements with Greatest Element on Right Side
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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. After doing so, return the array.
Source: Replace Elements with Greatest Element on Right Side on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
arr = [17,18,5,4,6,1]
Output
[18,6,6,6,1,-1]
# Example 2
Input
arr = [400]
Output
[-1]
Constraints
1 <= arr.length <= 10^4
1 <= arr[i] <= 10^5
Related LeetCode Problems
Practice more problems similar to Replace Elements with Greatest Element on Right Side.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.