diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1503. Last Moment Before All Ants Fall Out of a Plank.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1503. Last Moment Before All Ants Fall Out of a Plank.py" new file mode 100644 index 00000000..9e3b7662 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1503. Last Moment Before All Ants Fall Out of a Plank.py" @@ -0,0 +1,13 @@ +class Solution: + def getLastMoment(self, n: int, left: list[int], right: list[int]) -> int: + ''' + left = [3, 4] right = [0, 1] + left = [2, 3] right = [1, 2] + ''' + + left.sort() + right.sort() + return max(left[-1] if left else 0, n-right[0] if right else 0) + + + diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1695. Maximum Erasure Value.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1695. Maximum Erasure Value.py" new file mode 100644 index 00000000..e7b6f823 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1695. Maximum Erasure Value.py" @@ -0,0 +1,22 @@ +class Solution: + def maximumUniqueSubarray(self, nums: list[int]) -> int: + ans = 0 + left = 0 + right = 0 + n = len(nums) + + counter = defaultdict(int) + total = 0 + + for right in range(n): + rnum = nums[right] + while counter[rnum] == 1: + lnum = nums[left] + counter[lnum] -= 1 + total -= lnum + left +=1 + counter[rnum] +=1 + total += rnum + ans = max(ans, total) + + return ans