1299. Replace Elements with Greatest Element on Right Side Easy
1/**
2 * [1299] Replace Elements with Greatest Element on Right Side
3 *
4 * 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.
5 * After doing so, return the array.
6 *
7 * Example 1:
8 *
9 * Input: arr = [17,18,5,4,6,1]
10 * Output: [18,6,6,6,1,-1]
11 * Explanation:
12 * - index 0 --> the greatest element to the right of index 0 is index 1 (18).
13 * - index 1 --> the greatest element to the right of index 1 is index 4 (6).
14 * - index 2 --> the greatest element to the right of index 2 is index 4 (6).
15 * - index 3 --> the greatest element to the right of index 3 is index 4 (6).
16 * - index 4 --> the greatest element to the right of index 4 is index 5 (1).
17 * - index 5 --> there are no elements to the right of index 5, so we put -1.
18 *
19 * Example 2:
20 *
21 * Input: arr = [400]
22 * Output: [-1]
23 * Explanation: There are no elements to the right of index 0.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= arr.length <= 10^4
29 * 1 <= arr[i] <= 10^5
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/
35// discuss: https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn replace_elements(arr: Vec<i32>) -> Vec<i32> {
41 vec![]
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1299() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.