TATA 1MG Hiring Off-Campus OA (2024) | Replace Element with Greatest Element on Right Side
Question · Posted Jun 2026
Problem Statement Given an integer array arr, replace every element with the greatest element among the elements to its right, and replace the last element with -1. Return the modified array after performing the operation in-place. Example Input arr = [17,18,5,4,6,1] Output [18,6,6,6,1,-1] Explanation Index Original Value Greatest Element on Right 0 17 18 1 18 6 2 5 6 3 4 6 4 6 1 5 1 -1 Result: [18,6,6,6,1,-1] Constraints 1 <= arr.length <= 10^4 1 <= arr[i] ...
The full answer & interview discussion are available to premium members.
Log in Create a free account