Class Solution
java.lang.Object
g1201_1300.s1299_replace_elements_with_greatest_element_on_right_side.Solution
1299 - Replace Elements with Greatest Element on Right Side.<p>Easy</p>
<p>Given an array <code>arr</code>, replace every element in that array with the greatest element among the elements to its right, and replace the last element with <code>-1</code>.</p>
<p>After doing so, return the array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [17,18,5,4,6,1]</p>
<p><strong>Output:</strong> [18,6,6,6,1,-1]</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<p>index 0 –> the greatest element to the right of index 0 is index 1 (18).</p>
</li>
<li>
<p>index 1 –> the greatest element to the right of index 1 is index 4 (6).</p>
</li>
<li>
<p>index 2 –> the greatest element to the right of index 2 is index 4 (6).</p>
</li>
<li>
<p>index 3 –> the greatest element to the right of index 3 is index 4 (6).</p>
</li>
<li>
<p>index 4 –> the greatest element to the right of index 4 is index 5 (1).</p>
</li>
<li>
<p>index 5 –> there are no elements to the right of index 5, so we put -1.</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [400]</p>
<p><strong>Output:</strong> [-1]</p>
<p><strong>Explanation:</strong> There are no elements to the right of index 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= arr.length <= 10<sup>4</sup></code></li>
<li><code>1 <= arr[i] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
replaceElements
public int[] replaceElements(int[] arr)
-