MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / Solution

Class Solution

1813-maximum-erasure-value/maximum-erasure-value.cpp:2–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1
2class Solution {
3public:
4 int maximumUniqueSubarray(vector<int>& nums) {
5 ios::sync_with_stdio(false);
6cin.tie(nullptr);
7
8 set<long long int> a;
9 long long int i=0,ans=0,j=0,curr=0,n=nums.size();
10 while (j<n){
11 if (a.find(nums[j])==a.end()){
12 a.insert(nums[j]);
13 curr+=nums[j];
14 ans = max(ans,curr);
15 j++;
16 }
17 else{
18 a.erase(nums[i]);
19 curr-=nums[i];
20 i++;
21 }
22 }
23 return ans;
24 }
25};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected