Tap here to switch tabs
Problem
Submissions

Problem: Replace Elements with Greatest Element on Right Side

Replace Elements with Greatest Element on Right Side asks you to update each array value with the greatest value anywhere to its right, then put negative one in the final position and return it.

Statement

Given an integer array arr, replace every element in the array with the greatest element among all elements to its right, and replace the final element with −1-1.

Return the modified array.

Constraints:

  • 1≤1 \leq arr.length ≤104\leq 10^4

  • 1≤1 \leq arr[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Replace Elements with Greatest Element on Right Side

Replace Elements with Greatest Element on Right Side asks you to update each array value with the greatest value anywhere to its right, then put negative one in the final position and return it.

Statement

Given an integer array arr, replace every element in the array with the greatest element among all elements to its right, and replace the final element with −1-1.

Return the modified array.

Constraints:

  • 1≤1 \leq arr.length ≤104\leq 10^4

  • 1≤1 \leq arr[i] ≤105\leq 10^5