#๐Ÿ”’ Maximum Erasure Value

10 messages ยท Page 1 of 1 (latest)

echo pumice
#

You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements.

Return the maximum score you can get by erasing exactly one subarray.

An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).

Example 1:

Input: nums = [4,2,4,5,6]
Output: 17
Explanation: The optimal subarray here is [2,4,5,6].
Example 2:

Input: nums = [5,2,1,2,5,2,1,2,5]
Output: 8
Explanation: The optimal subarray here is [5,2,1] or [1,2,5].

[187,470,25,436,538,809,441,167,477,110,275,133,666,345,411,459,490,266,987,965,429,166,809,340,467,318,125,165,809,610,31,585,970,306,42,189,169,743,78,810,70,382,367,490,787,670,476,278,775,673,299,19,893,817,971,458,409,886,434]

Use Testcase

Output24864

Expected
16911

astral jettyBOT
#

@echo pumice

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

echo pumice
#

My code:

    def maximumUniqueSubarray(self, nums: List[int]) -> int:
        optimal = []
        seen = set()
        for j in range(len(nums)):
            if nums[j] in seen:
                continue
            else:
                seen.add(nums[j])
                optimal.append(nums[j])
        return sum(optimal)```
astral jettyBOT
#

Hey @echo pumice!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
echo pumice
#

Why it gives a wrong output?

trail comet
#

what you're doing is the sum of all unique elements, you forgot the part where it has to be a subarray (continious, e.g. in [x, y, z], [x, z] is not a subarray)

echo pumice
#

I didn't read that part

astral jettyBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.