3487. Maximum Unique Subarray Sum After Deletion Easy
1/**
2 * [3487] Maximum Unique Subarray Sum After Deletion
3 *
4 * You are given an integer array nums.
5 * You are allowed to delete any number of elements from nums without making it empty. After performing the deletions, select a <span data-keyword="subarray-nonempty">subarray</span> of nums such that:
6 * <ol>
7 * All elements in the subarray are unique.
8 * The sum of the elements in the subarray is maximized.
9 * </ol>
10 * Return the maximum sum of such a subarray.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [1,2,3,4,5]</span>
15 * Output: <span class="example-io">15</span>
16 * Explanation:
17 * Select the entire array without deleting any element to obtain the maximum sum.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [1,1,0,1,1]</span>
22 * Output: 1
23 * Explanation:
24 * Delete the element nums[0] == 1, nums[1] == 1, nums[2] == 0, and nums[3] == 1. Select the entire array [1] to obtain the maximum sum.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [1,2,-1,-2,1,0,-1]</span>
29 * Output: 3
30 * Explanation:
31 * Delete the elements nums[2] == -1 and nums[3] == -2, and select the subarray [2, 1] from [1, 2, 1, 0, -1] to obtain the maximum sum.
32 * </div>
33 *
34 * Constraints:
35 *
36 * 1 <= nums.length <= 100
37 * -100 <= nums[i] <= 100
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/maximum-unique-subarray-sum-after-deletion/
43// discuss: https://leetcode.com/problems/maximum-unique-subarray-sum-after-deletion/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn max_sum(nums: Vec<i32>) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_3487() {
61 }
62}
63Back
© 2026 bowen.ge All Rights Reserved.