question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-erasure-value | JS, Python, Java, C++ | Easy 2-Pointer Sliding Window Solution w/ Explanation | js-python-java-c-easy-2-pointer-sliding-se4c5 | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-05-28T07:44:07.250270+00:00 | 2021-05-28T07:57:28.437027+00:00 | 1,677 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nLike most problems that ask about a contiguous subarray, this problem naturally calls for a **2-pointer sliding window** approach. There are a... | 24 | 8 | ['C', 'Python', 'Java', 'JavaScript'] | 1 |
maximum-erasure-value | Python3 O(n) sliding window | python3-on-sliding-window-by-invinciblez-8d31 | \nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n ans = float(\'-inf\')\n cur = 0\n # sliding window; curre | invinciblezz | NORMAL | 2020-12-20T04:22:35.060781+00:00 | 2020-12-20T05:15:21.798189+00:00 | 2,214 | false | ```\nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n ans = float(\'-inf\')\n cur = 0\n # sliding window; current value = [i, j]\n seen = set()\n i = 0\n for j in range(len(nums)):\n while nums[j] in seen:\n cur -= nums[i... | 23 | 2 | [] | 3 |
maximum-erasure-value | Easy C++ Solution using Two Pointers | easy-c-solution-using-two-pointers-by-ha-v428 | The idea here is to keep track of all the elements already visited using a set and deploy two pointers (i&j) to adjust our current window.\nThe flow is as foll | harshit7962 | NORMAL | 2022-06-12T03:39:00.389703+00:00 | 2022-06-12T04:22:57.665144+00:00 | 4,037 | false | The idea here is to keep track of all the elements already visited using a set and deploy two pointers (i&j) to adjust our current window.\nThe flow is as follows:\n* If the current element is not already present in the set we simply add it to our curr_sum and extend the window...\n* If the element is already present ... | 22 | 1 | ['Two Pointers', 'C', 'C++'] | 1 |
maximum-erasure-value | ✅ Python Easy 2 approaches | python-easy-2-approaches-by-constantine7-flfm | \u2714\uFE0FSolution I - Two pointers using Counter\n\nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n counter=defaultdic | constantine786 | NORMAL | 2022-06-12T00:38:51.416693+00:00 | 2022-06-12T00:39:59.496054+00:00 | 2,823 | false | ## \u2714\uFE0F*Solution I - Two pointers using Counter*\n```\nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n counter=defaultdict(int) # track count of elements in the window\n res=i=tot=0\n\t\t\n for j in range(len(nums)):\n x=nums[j] \n to... | 19 | 0 | ['Python', 'Python3'] | 3 |
maximum-erasure-value | C++ Sliding window + hashmap 🥓🥓 | c-sliding-window-hashmap-by-midnightsimo-vo8r | Keep a frequency map of the numbers in the window.\n\nwhile the count of the latest number in the window is greater than 1, shrink the window.\n\nrecord the bes | midnightsimon | NORMAL | 2022-06-12T01:15:18.039801+00:00 | 2022-06-12T01:15:18.039825+00:00 | 3,029 | false | Keep a frequency map of the numbers in the window.\n\nwhile the count of the latest number in the window is greater than 1, shrink the window.\n\nrecord the best answer.\n\n**Solved LIVE ON TWITCH. Link in profile. I stream Everyday at 6pm PT** \n\n```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector... | 16 | 0 | [] | 3 |
maximum-erasure-value | Maximum Erasure Value | JS, Python, Java, C++ | Easy 2-Pointer Sliding Window Solution w/ Expl. | maximum-erasure-value-js-python-java-c-e-4roh | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-05-28T07:44:53.132051+00:00 | 2021-05-28T07:57:42.155194+00:00 | 551 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nLike most problems that ask about a contiguous subarray, this problem naturally calls for a **2-pointer sliding window** approach. There are a... | 16 | 6 | [] | 1 |
maximum-erasure-value | python3 || 9 lines, pref and dict || T/S: 99% / 44% | python3-9-lines-pref-and-dict-ts-99-44-b-t1vy | Here\'s the plan:\n1. We initialize vars and build a prefix array for nums.\n2. We use left to keep track of the starting index of the current subarray.\n3. We | Spaulding_ | NORMAL | 2022-06-12T17:29:04.790146+00:00 | 2024-06-06T21:14:35.772600+00:00 | 214 | false | Here\'s the plan:\n1. We initialize `vars` and build a prefix array for `nums`.\n2. We use `left` to keep track of the starting index of the current subarray.\n3. We use `d` to keep track of the latest indexplus 1 for each value `n` in `nums`. \n4. We iterate through nums, updating `left` (if neccessary), `d`, and `ans... | 13 | 0 | ['Python', 'Python3'] | 0 |
maximum-erasure-value | C++ Sliding Window 99% Faster No Library Hash Map O(1) Lookup time | c-sliding-window-99-faster-no-library-ha-4zlm | \nclass Solution {\npublic:\n \n int maximumUniqueSubarray(vector<int>& nums) {\n int res = 0;\n int currSum = 0;\n \n int m[1 | sputnik15963 | NORMAL | 2020-12-23T20:07:11.309855+00:00 | 2020-12-23T20:07:11.309897+00:00 | 1,570 | false | ```\nclass Solution {\npublic:\n \n int maximumUniqueSubarray(vector<int>& nums) {\n int res = 0;\n int currSum = 0;\n \n int m[100001] = {};\n //Value is the index in this map\n int i = 0;\n int j = 0;\n \n while( j < nums.size()){\n \n ... | 11 | 0 | ['C', 'Sliding Window'] | 1 |
maximum-erasure-value | ✅ C++ | Sliding Window | Hashmap | O(N) | c-sliding-window-hashmap-on-by-rupam66-jr3r | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int i=0,j=0,sum=0,res=0;\n unordered_map<int,int> mp;\n w | rupam66 | NORMAL | 2022-06-12T04:33:31.831756+00:00 | 2022-06-12T04:48:45.475992+00:00 | 1,448 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int i=0,j=0,sum=0,res=0;\n unordered_map<int,int> mp;\n while(j<nums.size()){\n if(mp[nums[j]]){ // nums[j] is already there in the window\n while(mp[nums[j]]){ // until the occurrence of ... | 10 | 0 | ['Two Pointers', 'C', 'Sliding Window'] | 3 |
maximum-erasure-value | C++ Sliding Window (+Cheat Sheet) | c-sliding-window-cheat-sheet-by-lzl12463-9xsv | See my latest update in repo LeetCode\n## Solution 1. Shrinkable Sliding Window\n\ncpp\n// OJ: https://leetcode.com/problems/maximum-erasure-value/\n// Author: | lzl124631x | NORMAL | 2021-10-05T08:01:46.004151+00:00 | 2021-10-05T08:01:46.004179+00:00 | 3,186 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n## Solution 1. Shrinkable Sliding Window\n\n```cpp\n// OJ: https://leetcode.com/problems/maximum-erasure-value/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(N)\nclass Solution {\npublic:\n int maximumUniqueSubarray(vect... | 9 | 0 | [] | 0 |
maximum-erasure-value | ✔C++|Sliding Window|Hash Table|O(N)🔥 | csliding-windowhash-tableon-by-xahoor72-ulp0 | Intuition\n Describe your first thoughts on how to solve this problem. \nIntuition is simple if u done some sliding window problems I suggest doing in same way | Xahoor72 | NORMAL | 2023-02-12T17:59:12.451327+00:00 | 2023-02-12T17:59:12.451365+00:00 | 780 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntuition is simple if u done some sliding window problems I suggest doing in same way as u have done those because there are little implementations techniques a liitle different than one another but idea is same or best is what is hittin... | 8 | 0 | ['Array', 'Hash Table', 'Sliding Window', 'C++'] | 0 |
maximum-erasure-value | O(n) Java Sliding Window Solution | on-java-sliding-window-solution-by-admin-q5gw | \n public int maximumUniqueSubarray(int[] nums) {\n int l =0, r = 0, length = nums.length, sum = 0;\n int[] map = new int[10001];\n int | admin007 | NORMAL | 2020-12-20T06:24:28.195001+00:00 | 2020-12-20T06:40:42.807833+00:00 | 938 | false | ```\n public int maximumUniqueSubarray(int[] nums) {\n int l =0, r = 0, length = nums.length, sum = 0;\n int[] map = new int[10001];\n int ans = 0;\n while (r < length) {\n map[nums[r]]++;\n sum += nums[r];\n r++;\n while (map[nums[r - 1]] >= 2)... | 8 | 2 | ['Java'] | 1 |
maximum-erasure-value | Java | Sliding Window | Easy to Understand | java-sliding-window-easy-to-understand-b-48v0 | Use a Sliding window to calculate the maximum sum subarray which has all unique elements. We can use a set to maintain the uniqueness.\n\n\nclass Solution {\n | rajarshi-sarkar | NORMAL | 2020-12-20T04:01:11.257148+00:00 | 2020-12-20T04:02:37.179689+00:00 | 970 | false | Use a Sliding window to calculate the maximum sum subarray which has all unique elements. We can use a set to maintain the uniqueness.\n\n```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n Set<Integer> set = new HashSet<>();\n \n int start = 0, n = nums.length, sum = 0, ans... | 8 | 0 | ['Sliding Window', 'Ordered Set', 'Java'] | 1 |
maximum-erasure-value | Maximum Erasure Value | maximum-erasure-value-by-shailu00-ynwd | C++ Code\n\nint maximumUniqueSubarray(vector<int>& nums) {\n int n= nums.size(),psum=0,mx=0,j=0,count=-1; unordered_map<int, pair<int, int>>m;\n f | Shailu00 | NORMAL | 2022-06-13T05:55:03.290109+00:00 | 2022-07-02T19:22:56.317482+00:00 | 124 | false | **C++ Code**\n```\nint maximumUniqueSubarray(vector<int>& nums) {\n int n= nums.size(),psum=0,mx=0,j=0,count=-1; unordered_map<int, pair<int, int>>m;\n for(int i=0; i<n; i++)\n {\n psum+=nums[i];\n if(m.find(nums[i])!=m.end() && m[nums[i]].second >=j )\n {\n ... | 7 | 0 | ['C'] | 2 |
maximum-erasure-value | Maximum Erasure Value Daily June ,Day12,22 | maximum-erasure-value-daily-june-day1222-vfhr | \nSteps:-\n Step 1: Creating prefix sum array\n\t Step 2: Iterating over nums from index 1 and initialized the result with res=nums[0]\n\t Step 3: Usi | omgupta0312 | NORMAL | 2022-06-12T11:05:15.072026+00:00 | 2022-06-12T11:05:15.072055+00:00 | 402 | false | ```\nSteps:-\n Step 1: Creating prefix sum array\n\t Step 2: Iterating over nums from index 1 and initialized the result with res=nums[0]\n\t Step 3: Using unordered_map cheching if element already present or not,\n\t Step 4: If present then checking if the index is greater than the start index. If True the... | 6 | 0 | ['C', 'Sliding Window', 'Prefix Sum'] | 3 |
maximum-erasure-value | C++ | O(n) | Single-pass | Map + Prefix Sum | c-on-single-pass-map-prefix-sum-by-shikh-4o23 | The goal of the algorithm to solve this problem was to maximize sum(i,j) such that all elements from i to j are unique (where sum(i,j) for array A is A[i] + A[i | shikhar03Stark | NORMAL | 2022-06-10T12:04:55.053007+00:00 | 2022-06-10T12:05:34.021964+00:00 | 390 | false | The goal of the algorithm to solve this problem was to **maximize** `sum(i,j)` such that all elements from **i** to **j** are **unique** (where `sum(i,j)` for array `A` is `A[i] + A[i+1] + .. A[j-1] + A[j]`).\nWe can think it in terms of **j**, for every **j**, we want to find the **left-most** point in the array such ... | 6 | 0 | ['Two Pointers', 'C', 'Prefix Sum'] | 1 |
maximum-erasure-value | [Python] Easy PREFIX SUM | python-easy-prefix-sum-by-aatmsaat-n6is | Maximum Erasure Value\n\n\nLets assume for array [1, 2, 5, 2, 5, 1] \n\n Padding :- we add 0 in the beginning of array to prevent Index_Out_Bound error then arr | aatmsaat | NORMAL | 2021-05-28T11:24:29.061736+00:00 | 2021-05-29T05:53:40.083770+00:00 | 444 | false | # Maximum Erasure Value\n\n\nLets assume for array *[1, 2, 5, 2, 5, 1]* \n\n* `Padding :- ` we add 0 in the beginning of array to prevent **Index_Out_Bound** error then array **nums** becomes *[0, 1, 2, 5, 2, 5, 1]*\n* `Index Array :-` we create the index array **Idxarr** which can be formed of the length of maximum el... | 6 | 2 | ['Prefix Sum', 'Python'] | 1 |
maximum-erasure-value | [C++] Sliding Window - Clear and Concise - O(n) | c-sliding-window-clear-and-concise-on-by-fekx | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int,bool> um;\n int n = nums.size();\n int | morning_coder | NORMAL | 2021-05-28T07:33:46.128379+00:00 | 2021-05-28T07:33:46.128420+00:00 | 688 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int,bool> um;\n int n = nums.size();\n int start = 0;\n int curr_sum = 0;\n int max_sum = 0;\n for(int i = 0; i < n; i++){\n while(um[nums[i]] == true){\n ... | 6 | 3 | ['Two Pointers', 'C', 'Sliding Window', 'C++'] | 1 |
maximum-erasure-value | ✅C++ | ✅Use Sliding window and hashing | ✅Simple and efficient solution | 🗓️ DLC June, Day 12 | c-use-sliding-window-and-hashing-simple-jg5ve | Please upvote if it helps \u2764\uFE0F\uD83D\uDE0A\nTC: O(N), SC: O(2N) ~ O(N)\n\nCode:\n\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& | Yash2arma | NORMAL | 2022-06-12T13:55:04.244846+00:00 | 2022-06-12T13:55:04.244881+00:00 | 601 | false | **Please upvote if it helps \u2764\uFE0F\uD83D\uDE0A**\n**TC: O(N), SC: O(2N) ~ O(N)**\n\n**Code:**\n```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) \n {\n int l=0, r=0; //define left and right pointers for sliding windows approach\n \n vector<int> sum_arr; //sum... | 5 | 0 | ['C', 'Sliding Window', 'C++'] | 0 |
maximum-erasure-value | cpp solution || hash table || 99.76 % faster and 99.27% space efficient || Two-Pointer | cpp-solution-hash-table-9976-faster-and-8u54m | Thank you for checking out my solution\nDo upvote if it helped :)\n_\n_Approach 1 : Brute Force (Will Fail as per the Constraints)\n__Brute force approach could | TheCodeAlpha | NORMAL | 2022-06-12T13:23:38.028073+00:00 | 2022-06-12T13:24:34.376577+00:00 | 334 | false | __Thank you for checking out my solution\nDo upvote if it helped :)__\n____\n__Approach 1 : Brute Force (Will Fail as per the Constraints)__\n__Brute force approach could be to set a quadratic algorithm\nSet up an answer variable as ans = 0 \nInitialise a new set__\n__Where the outer loop marks a starting position__\n>... | 5 | 0 | ['Two Pointers', 'Sliding Window', 'C++'] | 1 |
maximum-erasure-value | ✔Easy 🔥Intuition 🟢Full explanations 🚀 All Lan code | easy-intuition-full-explanations-all-lan-t1t0 | Logic\n This problem is about to find the maximum sum of subarrray (where elements in subarray is unique) in an array.\n This is a classic Sliding Window proble | nitin23rathod | NORMAL | 2022-06-12T09:42:00.467312+00:00 | 2022-06-12T09:42:00.467372+00:00 | 247 | false | **Logic**\n* This problem is about to find the maximum sum of subarrray (where elements in subarray is unique) in an array.\n* This is a classic Sliding Window problem which is simillar to this problem 3. Longest Substring Without Repeating Characters\n* We use seen (HashMap) to keep track of last index of a number.\n*... | 5 | 0 | ['C', 'Python', 'Java'] | 0 |
maximum-erasure-value | Intentionally confusing and short: Tuples and one-letter variable names | intentionally-confusing-and-short-tuples-2h21 | csharp\npublic int MaximumUniqueSubarray(int[] a)\n{\n\tvar (h, m, s, f) = (new HashSet<int>(), 0, 0, 0);\n\tforeach(int n in a)\n\t{\n\t\twhile(!h.Add(n)) (_, | anikit | NORMAL | 2022-06-12T07:05:51.947808+00:00 | 2023-01-03T21:48:05.962148+00:00 | 205 | false | ```csharp\npublic int MaximumUniqueSubarray(int[] a)\n{\n\tvar (h, m, s, f) = (new HashSet<int>(), 0, 0, 0);\n\tforeach(int n in a)\n\t{\n\t\twhile(!h.Add(n)) (_, s, f) = (h.Remove(a[f]), s - a[f], f + 1);\n\t\t(s, m) = (s + n, Math.Max(m, s + n));\n\t}\n\treturn m;\n}\n```\n\nLegend:\n`a` - our input **a**rray\n`h` - ... | 5 | 0 | ['C#'] | 0 |
maximum-erasure-value | C++ || Sliding window || map || 1695. Maximum Erasure Value | c-sliding-window-map-1695-maximum-erasur-k8bu | \t//\tInitially we will keep our i and j pointer at index 0 \n\t//\tkeep moving j and add the current no to sum and \n\t//\talso add the curr no to map \n\t//\t | anubhavsingh11 | NORMAL | 2022-06-12T05:35:43.792151+00:00 | 2022-06-12T05:35:43.792197+00:00 | 232 | false | \t//\tInitially we will keep our i and j pointer at index 0 \n\t//\tkeep moving j and add the current no to sum and \n\t//\talso add the curr no to map \n\t//\tat each step update the ans\n\t// whenever any element comes which is already in map\n\t// then start increasing i pointer and erase nums[i]\n\t// from ma... | 5 | 0 | ['C', 'Sliding Window'] | 0 |
maximum-erasure-value | WEEB DOES PYTHON SLIDING WINDOW (BEATS 98.41%) | weeb-does-python-sliding-window-beats-98-y5ne | \n\n\tclass Solution:\n\t\tdef maximumUniqueSubarray(self, nums: List[int]) -> int:\n\t\t\tlow = 0\n\t\t\tvisited = set()\n\t\t\tresult = 0\n\t\t\tcurSum = 0\n\ | Skywalker5423 | NORMAL | 2021-12-25T03:04:40.724919+00:00 | 2021-12-25T03:04:40.724957+00:00 | 671 | false | \n\n\tclass Solution:\n\t\tdef maximumUniqueSubarray(self, nums: List[int]) -> int:\n\t\t\tlow = 0\n\t\t\tvisited = set()\n\t\t\tresult = 0\n\t\t\tcurSum = 0\n\t\t\tfor high in range(len(nums)):\n\t\t\t\twhile ... | 5 | 0 | ['Two Pointers', 'Sliding Window', 'Ordered Set', 'Python', 'Python3'] | 2 |
maximum-erasure-value | C++ Sliding Window and Set | c-sliding-window-and-set-by-hmmonotone-hnxe | The idea here is to always have a subarray with no duplicate element. This is where set comes into picture to store the elements from i to j.\nThis will be more | hmmonotone | NORMAL | 2021-05-28T15:31:15.876718+00:00 | 2021-05-28T15:31:15.876762+00:00 | 273 | false | The idea here is to always have a subarray with no duplicate element. This is where `set` comes into picture to store the elements from `i` to `j`.\nThis will be more clear from the code:\n```\n int maximumUniqueSubarray(vector<int>& nums) {\n int sum=0,curr=0;\n unordered_set<int> s;\n int i=0,... | 5 | 0 | ['C', 'Sliding Window', 'Ordered Set'] | 0 |
maximum-erasure-value | Python O(N) solution, 6 lines, use dictionary | python-on-solution-6-lines-use-dictionar-nll4 | use a dictionary to keep the index of each number.\n\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n res, start, dic, sumDic = 0, 0, {}, | wing1001 | NORMAL | 2020-12-20T07:04:26.423481+00:00 | 2021-01-01T06:53:41.670812+00:00 | 441 | false | use a dictionary to keep the index of each number.\n```\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n res, start, dic, sumDic = 0, 0, {}, {-1:0} \n for i in range(len(nums)):\n sumDic[i] = sumDic[i-1] + nums[i]\n if nums[i] not in dic or dic[nums[i]] < start: \n ... | 5 | 3 | [] | 1 |
maximum-erasure-value | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-flsl | \n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n | shishirRsiam | NORMAL | 2024-09-11T01:00:49.369350+00:00 | 2024-09-11T01:00:49.369373+00:00 | 211 | false | \n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) \n {\n // Declare a map to keep... | 4 | 0 | ['Array', 'Hash Table', 'Sliding Window', 'C++'] | 6 |
maximum-erasure-value | TIME & SPACE 99% BEATS || C++ || SLIDING WINDOW | time-space-99-beats-c-sliding-window-by-epqpt | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n vector<int> v(1e4+2);\n int i = 0, j = 0, n = nums.size(),sum = | yash___sharma_ | NORMAL | 2023-02-11T05:37:23.124914+00:00 | 2023-02-11T05:37:23.124945+00:00 | 488 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n vector<int> v(1e4+2);\n int i = 0, j = 0, n = nums.size(),sum = 0,ans = 0;\n while(i<n){\n sum += nums[i];\n v[nums[i]]++;\n while(v[nums[i]]==2){\n sum -= nums[j];\n... | 4 | 0 | ['Two Pointers', 'C', 'Sliding Window', 'C++'] | 0 |
maximum-erasure-value | Go - Sliding window - O(n) with hashmap | go-sliding-window-on-with-hashmap-by-tua-866t | \nfunc maximumUniqueSubarray(nums []int) int {\n if len(nums) == 0 {return 0}\n if len(nums) == 1 {return nums[0]}\n \n res := -1 << 63\n \n m | tuanbieber | NORMAL | 2022-06-20T15:09:59.547408+00:00 | 2022-06-20T15:09:59.547455+00:00 | 133 | false | ```\nfunc maximumUniqueSubarray(nums []int) int {\n if len(nums) == 0 {return 0}\n if len(nums) == 1 {return nums[0]}\n \n res := -1 << 63\n \n m := make(map[int]int)\n m[nums[0]]++\n l, sum := 0, nums[0]\n \n for i := 1; i < len(nums); i++ {\n sum+= nums[i]\n m[nums[i]]++\n ... | 4 | 0 | ['Go'] | 0 |
maximum-erasure-value | C++ Maps + Sum Based Two Pointers | c-maps-sum-based-two-pointers-by-82877ha-u8rd | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n // ekk map banaloooo\n \n // hum ekk map bana lengeeeee | 82877harsh | NORMAL | 2022-06-12T15:26:17.761162+00:00 | 2022-06-12T15:26:17.761199+00:00 | 283 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n // ekk map banaloooo\n \n // hum ekk map bana lengeeeee uske baad max lenge so jo sabse longest side ka map hogaaa wo le lengeeeeeeeee............\n map<int,int>harsh;\n int maxi=INT_MIN;\n in... | 4 | 0 | ['C'] | 0 |
maximum-erasure-value | Simple, Easy and Faster O(n) solution | simple-easy-and-faster-on-solution-by-un-qbuj | class Solution {\npublic:\n\n int maximumUniqueSubarray(vector& nums) {\n unordered_map m;\n vector arr(vector(nums.size(),0));\n arr[0 | unraveler00 | NORMAL | 2022-06-12T14:32:48.278290+00:00 | 2022-06-12T14:32:48.278340+00:00 | 95 | false | class Solution {\npublic:\n\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int,int> m;\n vector<int> arr(vector<int>(nums.size(),0));\n arr[0] = nums[0];\n \n int max=0, prev=0,sum=0;\n for(int i=0; i<nums.size(); i++) {\n sum+=nums[i];\n ... | 4 | 0 | ['Two Pointers', 'C', 'Sliding Window'] | 0 |
maximum-erasure-value | Java O(n) Sliding Window With HashSet With Photos and Explanation | java-on-sliding-window-with-hashset-with-hg3o | \n\n\n\n\n\n\n\n\n\n\n\n```\nclass Solution {\n \tpublic static int maximumUniqueSubarray(int[] nums) {\n\n // HashSet to check if the next value is un | mertpinarbasi | NORMAL | 2022-06-12T14:08:16.547549+00:00 | 2022-06-12T14:08:16.547571+00:00 | 764 | false | \n\n\n\n\n\n\n\n\n\n\n\n```\nclass Solution {\n \tpublic static int maximumUniqueSubarray(int[] nums) {\n\n // HashSet to check if the next value is unique.\n\t\tSet<Integer> set = new HashSet<>();\n ... | 4 | 0 | ['Sliding Window', 'Java'] | 0 |
maximum-erasure-value | C++ || No Hashmap || Simple and easy solution | c-no-hashmap-simple-and-easy-solution-by-rfk4 | \n int maximumUniqueSubarray(vector<int>& nums) {\n vector<int> m(10001); // use this to store frequency as it is faster than map\n int | ashay028 | NORMAL | 2022-06-12T12:16:32.977912+00:00 | 2022-06-12T12:16:32.977946+00:00 | 70 | false | ```\n int maximumUniqueSubarray(vector<int>& nums) {\n vector<int> m(10001); // use this to store frequency as it is faster than map\n int n=nums.size(),ans=0,start=0,end=0,sum=0;\n while(end<n)\n {\n sum+=nums[end];\n m[nums[end]]++;\n while(m[nums... | 4 | 0 | ['Array', 'Two Pointers'] | 0 |
maximum-erasure-value | ✅C++ || Using Prefix Sum & MAP || 🗓️ Daily LeetCoding Challenge June, Day 12 | c-using-prefix-sum-map-daily-leetcoding-u1tka | Please Upvote If It Helps\n\n\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) \n {\n //finding subarray(with unique eleme | mayanksamadhiya12345 | NORMAL | 2022-06-12T06:11:43.144341+00:00 | 2022-06-12T06:11:43.144370+00:00 | 167 | false | **Please Upvote If It Helps**\n\n```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) \n {\n //finding subarray(with unique elements) with maximum score\n int score = -1;\n \n //storing index of the elements\n vector<int> map(1e4+1, -1); \n \n ... | 4 | 0 | [] | 0 |
maximum-erasure-value | C++ | 106ms[O(n)] & 89 MB[O(|a[i]|)] (100%/99.9%) | two - pointer | explanation | c-106mson-89-mboai-100999-two-pointer-ex-uzx2 | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n bool DP[10001]={};\n int ans=0,r=0,tmp=0;\n for(int i=0;i | SunGod1223 | NORMAL | 2022-06-12T01:54:16.320391+00:00 | 2022-06-15T03:17:02.649342+00:00 | 70 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n bool DP[10001]={};\n int ans=0,r=0,tmp=0;\n for(int i=0;i<nums.size();++i){\n while(r<nums.size()&&!DP[nums[r]]){\n DP[nums[r]]=1;\n tmp+=nums[r++];\n }\n ... | 4 | 0 | ['Two Pointers', 'C'] | 0 |
maximum-erasure-value | [C++] 76ms, Fastest Solution to Date Explained, 100% Time, ~90% Space | c-76ms-fastest-solution-to-date-explaine-p6sh | This problem is clearly a sliding window problem, with the extra twist of a variable size of the window.\n\nTo solve it, we will need to build a running total o | ajna | NORMAL | 2021-05-29T01:02:19.350400+00:00 | 2021-05-29T01:16:42.714078+00:00 | 285 | false | This problem is clearly a sliding window problem, with the extra twist of a variable size of the window.\n\nTo solve it, we will need to build a running total of all the values in the input, minus the total up to the last repeated element we encountered.\n\nThis would call for a hashmap (or an `unordered_map` in C++), ... | 4 | 0 | ['C', 'C++'] | 0 |
maximum-erasure-value | Python, prefix sum O(N) | python-prefix-sum-on-by-warmr0bot-u97e | First calculate the prefix sum, then do a single pass recording last seen positions for each element. \nThese will serve as breaking points for the array.\n\nde | warmr0bot | NORMAL | 2020-12-20T04:20:44.724601+00:00 | 2020-12-20T04:20:44.724640+00:00 | 434 | false | First calculate the prefix sum, then do a single pass recording last seen positions for each element. \nThese will serve as breaking points for the array.\n```\ndef maximumUniqueSubarray(self, nums: List[int]) -> int:\n\tprefix = [0]\n\tfor i in range(len(nums)):\n\t\tprefix += [prefix[-1] + nums[i]]\n\n\tlastpos = {}\... | 4 | 0 | ['Prefix Sum', 'Python', 'Python3'] | 0 |
maximum-erasure-value | Sliding window & Two Pointers Pattern | sliding-window-two-pointers-pattern-by-d-dw28 | the sum of unique "subArray" elemets is added\n\n# Code\njava []\nimport java.util.HashMap;\n\nclass Solution {\n public int maximumUniqueSubarray(int[] nums | Dixon_N | NORMAL | 2024-05-20T02:32:40.975575+00:00 | 2024-05-20T15:14:30.526029+00:00 | 246 | false | the sum of unique "subArray" elemets is added\n\n# Code\n```java []\nimport java.util.HashMap;\n\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n HashMap<Integer, Integer> map = new HashMap<>();\n int left = 0, right = 0, sum = 0, maxSum = 0;\n\n while (right < nums.length) {... | 3 | 0 | ['Java'] | 2 |
maximum-erasure-value | BEST SOLUTION -- 2 POINTERS -- EASIEST TO UNDERSTAND -- BEATS 98% | best-solution-2-pointers-easiest-to-unde-85eu | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n Keep SLIDING the " | Skaezr73 | NORMAL | 2023-08-11T16:36:30.131610+00:00 | 2023-08-11T16:36:30.131638+00:00 | 78 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n Keep <b>SLIDING </> the "end" pointer in each iteration. slide the start pointer only when duplicate is found! \n# Complexity\n- Time complexity:\n<!-- Add your ti... | 3 | 0 | ['Python'] | 1 |
maximum-erasure-value | Sliding Window , Easy C++ ✅✅ | sliding-window-easy-c-by-deepak_5910-fy5f | Approach\n Describe your approach to solving the problem. \nUse Sliding Window to find out the maximum Sum of the Subarray With Unique Elements.\n# Complexity\n | Deepak_5910 | NORMAL | 2023-07-10T13:47:03.783021+00:00 | 2023-07-10T13:47:03.783050+00:00 | 147 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nUse **Sliding Window** to find out the **maximum Sum** of the Subarray With **Unique Elements**.\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity he... | 3 | 0 | ['Sliding Window', 'C++'] | 0 |
maximum-erasure-value | [Java] Sliding window. O(n) Time. O(1) Space. Clean code with comments and dry run | java-sliding-window-on-time-o1-space-cle-qoc3 | Approach\nUse a sliding window, and keep moving left pointer to get rid of duplicate elements.\nHave a variable to store maxScore.\n\n// Time complexity: O(n) l | new_at_school | NORMAL | 2022-06-12T13:37:18.364482+00:00 | 2022-06-12T14:03:51.244876+00:00 | 309 | false | **Approach**\nUse a sliding window, and keep moving left pointer to get rid of duplicate elements.\nHave a variable to store maxScore.\n```\n// Time complexity: O(n) linear\n// Space complexity: O(1) constant - actually O(100_001)\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n int n = nu... | 3 | 0 | ['Sliding Window'] | 0 |
maximum-erasure-value | Easy Python Solution | easy-python-solution-by-prernaarora221-r76w | ```\nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n s = set()\n sum1 = 0\n start = 0\n m = 0\n | prernaarora221 | NORMAL | 2022-06-12T13:35:21.414848+00:00 | 2022-06-12T13:35:21.414886+00:00 | 235 | false | ```\nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n s = set()\n sum1 = 0\n start = 0\n m = 0\n for i in range(len(nums)):\n while nums[i] in s:\n s.remove(nums[start])\n sum1 -= nums[start]\n star... | 3 | 0 | ['Python'] | 0 |
maximum-erasure-value | talks are shit show me code | talks-are-shit-show-me-code-by-fr1nkenst-8kv6 | \nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n int s[]=new int[nums.length];\n s[0]=nums[0];\n for(int i=1;i<nums | fr1nkenstein | NORMAL | 2022-06-12T07:13:23.591821+00:00 | 2022-06-12T07:13:23.591871+00:00 | 101 | false | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n int s[]=new int[nums.length];\n s[0]=nums[0];\n for(int i=1;i<nums.length;i++)s[i]+=s[i-1]+nums[i];\n int p[]=new int[1000000];\n Arrays.fill(p,-1);\n int ans=0,b=0;\n for(int i=0;i<nums.length;i... | 3 | 1 | ['Two Pointers'] | 1 |
maximum-erasure-value | [Java] Sliding Window + HashMap | With Explanation | java-sliding-window-hashmap-with-explana-mdmh | the question is similar with 3. Longest Substring Without Repeating Characters\n\n\n### Intuition\nthe goal is to find the max sum subarray with unique elements | visonli | NORMAL | 2022-06-12T07:07:25.932492+00:00 | 2022-06-12T07:14:43.818024+00:00 | 365 | false | > the question is similar with [3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)\n\n\n### Intuition\nthe goal is to find the max sum subarray with unique elements\nsince the elements are positive numbers, we can use sliding window approach... | 3 | 0 | ['Java'] | 0 |
maximum-erasure-value | C++ | Two Pointer | Easy | c-two-pointer-easy-by-victor_knox-9umz | The idea is to have two pointers/sliding window which tracks the sum of the elements inside the window.\nHere\'s how the sliding window works: \n1. To keep trac | Victor_Knox | NORMAL | 2022-06-12T03:44:26.077641+00:00 | 2022-06-12T03:52:14.013470+00:00 | 515 | false | The idea is to have two pointers/sliding window which tracks the sum of the elements inside the window.\nHere\'s how the sliding window works: \n1. To keep track of your unique numbers, initialize a map. \n2. If you see a new number, add it to your window and sum and map(pretty simple).\n3. If you see a repeated number... | 3 | 0 | ['Two Pointers', 'C'] | 0 |
maximum-erasure-value | Python3 solution | set | faster than 88% | python3-solution-set-faster-than-88-by-f-n9fv | \'\'\'\nUpvote if you like it\n\nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n msf = -9999 # max sum so far\n me | FlorinnC1 | NORMAL | 2021-08-02T13:03:15.998766+00:00 | 2021-08-02T13:04:24.915914+00:00 | 342 | false | \'\'\'\nUpvote if you like it\n```\nclass Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:\n msf = -9999 # max sum so far\n meh = 0 # max sum ending here\n s = set()\n j = 0\n i = 0\n while j < len(nums):\n meh += nums[j]\n while num... | 3 | 0 | ['Ordered Set', 'Python', 'Python3'] | 1 |
maximum-erasure-value | Simple C++ Solution using hashset with comments | simple-c-solution-using-hashset-with-com-5i9c | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n // Creating hashset for quick access\n unordered_set<int> set;\n | amratyasaraswat | NORMAL | 2021-05-29T07:08:42.009684+00:00 | 2021-05-29T07:08:42.009724+00:00 | 131 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n // Creating hashset for quick access\n unordered_set<int> set;\n int n = nums.size();\n int i = 0, j = 0, sum = 0, ans =0;\n // Looping until we reach last elemenet\n while (i < n and j < n){\n... | 3 | 0 | ['Sliding Window'] | 0 |
maximum-erasure-value | Classical Sliding Window problem. | classical-sliding-window-problem-by-sunn-bg1y | This is a classical problem where sliding window technique is used.\n\nSliding window is a technique in which we are interested in looking at a window of consec | sunnygupta | NORMAL | 2021-05-28T12:59:32.627992+00:00 | 2021-05-28T13:02:31.058023+00:00 | 54 | false | This is a classical problem where sliding window technique is used.\n\nSliding window is a technique in which we are interested in looking at a window of consecutive elements, for example:\nIf we have an array arr[]={ 1, 2, 3, 4, 5 }, then the sliding window between 2nd and 4th element would be: { 2, 3, 4 }.\n\nAnother... | 3 | 0 | [] | 1 |
maximum-erasure-value | C++ - two pointers, O(n) - faster than 93.5% time and 85% memory | c-two-pointers-on-faster-than-935-time-a-4kx2 | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int l = 0, r = 0, maxSum = 0, tempSum = 0;\n vector<int> occuren | abilda | NORMAL | 2021-05-28T11:32:13.407661+00:00 | 2021-05-28T11:33:28.352374+00:00 | 148 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int l = 0, r = 0, maxSum = 0, tempSum = 0;\n vector<int> occurences(1e4+1, 0);\n while (r < nums.size()) \n\t\t\tif (occurences[nums[r]] == 0) {\n occurences[nums[r]]++;\n tempSum += n... | 3 | 0 | ['C'] | 0 |
maximum-erasure-value | ✅ Maximum Erasure Value | Easy Sliding Window Solution | maximum-erasure-value-easy-sliding-windo-avoi | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int,int> mp;\n int i=0;\n int sum=0;\n | shivaye | NORMAL | 2021-05-28T07:41:50.559746+00:00 | 2021-05-28T07:41:50.559795+00:00 | 96 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int,int> mp;\n int i=0;\n int sum=0;\n int ans=0;\n for(int j=0;j<nums.size();j++)\n {\n sum+=nums[j];\n mp[nums[j]]++;\n while(mp[nums[j]]>1)\n ... | 3 | 3 | ['C'] | 0 |
maximum-erasure-value | Sliding Window || O(N) || HashMap | sliding-window-on-hashmap-by-faltu_admi-yyac | \nclass Solution {\n public:\n int maximumUniqueSubarray(vector<int>& nums) {\n int n = nums.size(), l = 0, r = 0, sum = 0, maxSum = 0;\n uno | faltu_admi | NORMAL | 2021-05-28T07:26:04.651369+00:00 | 2021-05-28T07:26:04.651408+00:00 | 102 | false | ```\nclass Solution {\n public:\n int maximumUniqueSubarray(vector<int>& nums) {\n int n = nums.size(), l = 0, r = 0, sum = 0, maxSum = 0;\n unordered_map<int, int> seen;\n\n while (r < n) {\n if (seen.count(nums[r]) == 0) {\n seen[nums[l]]--;\n sum -= ... | 3 | 0 | [] | 0 |
maximum-erasure-value | Javascript | Sliding Window Solution w/ Explanation | 100% / 100% | javascript-sliding-window-solution-w-exp-qjg6 | In order to solve this in O(n) time, we can use a sliding window to evaluate all usable subarrays. For that, we\'ll need to use some data type to keep track of | sgallivan | NORMAL | 2020-12-24T20:24:41.771645+00:00 | 2020-12-24T20:24:41.771679+00:00 | 273 | false | In order to solve this in **O(n)** time, we can use a sliding window to evaluate all usable subarrays. For that, we\'ll need to use some data type to keep track of the numbers in our sliding window. \n\nNormally, I would use a **Map** to keep track of this information, but because we\'re using numbers as keys and becau... | 3 | 0 | ['Sliding Window', 'JavaScript'] | 0 |
maximum-erasure-value | a few solutions | a-few-solutions-by-claytonjwong-kssj | LeetCode Daily: June 12th 2022\n\nUse a sliding window i..j inclusive tracking total t sum of uniquely seen values of the input array A to find and return the b | claytonjwong | NORMAL | 2020-12-20T04:10:46.321900+00:00 | 2022-06-12T16:37:53.530734+00:00 | 205 | false | **LeetCode Daily: June 12<sup>th</sup> 2022**\n\nUse a sliding window `i..j` inclusive tracking total `t` sum of uniquely `seen` values of the input array `A` to find and return the `best` total `t` sum.\n\n*Kotlin*\n```\nclass Solution {\n fun maximumUniqueSubarray(A: IntArray): Int {\n var best = 0\n ... | 3 | 0 | [] | 1 |
maximum-erasure-value | Kotlin - Typical Sliding Window Approach with a HashSet | kotlin-typical-sliding-window-approach-w-n4j5 | Solution - github\n\nProblem List\n#SlidingWindow - github\n#Subarray - github\n\n\n/**\n * @author: Leon\n * https://leetcode.com/problems/maximum-erasure-valu | idiotleon | NORMAL | 2020-12-20T04:10:18.047011+00:00 | 2022-07-06T01:43:30.045678+00:00 | 273 | false | Solution - [github](https://github.com/An7One/leetcode-solutions-kotlin-an7one/tree/main/src/main/kotlin/com/an7one/leetcode/lvl3/lc1695)\n\n<b>Problem List</b>\n#SlidingWindow - [github](https://github.com/An7One/leetcode-problems-by-tag-an7one/tree/main/txt/by_technique/n_pointers/by_pointer_amount/2_pointers/sliding... | 3 | 0 | ['Two Pointers', 'Sliding Window', 'Kotlin'] | 0 |
maximum-erasure-value | Typescript with hashmap + sliding window, O(n) time | typescript-with-hashmap-sliding-window-o-lnra | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | nhat_nguyen123 | NORMAL | 2024-09-22T04:51:32.688940+00:00 | 2024-09-22T04:51:32.688971+00:00 | 15 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $... | 2 | 0 | ['TypeScript'] | 0 |
maximum-erasure-value | 100% beat sliding window concept | 100-beat-sliding-window-concept-by-somay-ykpz | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | somaycoder | NORMAL | 2024-04-27T12:45:11.759641+00:00 | 2024-04-27T12:45:11.759670+00:00 | 177 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Array', 'Hash Table', 'Sliding Window', 'C++'] | 1 |
maximum-erasure-value | Two Pointers with HashSet Solution (with step by step explanationTwo) | two-pointers-with-hashset-solution-with-o91cy | Intuition\nWe will use two pointer approach with HashSet to solve this problem\n# Approach\nWe declare HashSet to check for unique in our window, then we iterat | alekseyvy | NORMAL | 2023-09-28T18:15:36.747108+00:00 | 2023-09-28T18:15:36.747138+00:00 | 54 | false | # Intuition\nWe will use two pointer approach with HashSet to solve this problem\n# Approach\nWe declare HashSet to check for unique in our window, then we iterate over nums array, and check if num at right pointer unique to our sub array that we collect in window set, if we found that it\'s not unique then we delete n... | 2 | 0 | ['Hash Table', 'Two Pointers', 'TypeScript'] | 1 |
maximum-erasure-value | PrefixSum Array + Sliding Window || Easy Solution | prefixsum-array-sliding-window-easy-solu-dwmg | Intuition\n Describe your first thoughts on how to solve this problem. \nPrefixSum Array + Sliding Window \n\n# Approach\n Describe your approach to solving t | ha_vi_ag- | NORMAL | 2023-01-05T07:03:22.960167+00:00 | 2023-01-05T07:05:51.045997+00:00 | 376 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nPrefixSum Array + Sliding Window \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can use the concept of prefix sum array to currect our current window sum in case of repeating element.\n\n# Complexity\n- Time... | 2 | 0 | ['Python3'] | 1 |
maximum-erasure-value | ✅ C++ ||Simple Solution || Hashmap || Sliding Window | c-simple-solution-hashmap-sliding-window-y49u | Also Try https://leetcode.com/problems/longest-substring-without-repeating-characters/ with same Approach\n\n\nclass Solution {\npublic:\n int maximumUnique | Yogesh02 | NORMAL | 2022-06-16T14:18:05.047437+00:00 | 2022-06-16T14:18:05.047478+00:00 | 165 | false | Also Try https://leetcode.com/problems/longest-substring-without-repeating-characters/ with same Approach\n\n```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int,int>mp;\n int maxi=0;\n int i=0;\n int j=0;\n int sum=0;\n while(j... | 2 | 0 | ['C', 'Sliding Window', 'C++'] | 0 |
maximum-erasure-value | C++ || Maximum Erasure Value || O(n) | c-maximum-erasure-value-on-by-ronit-khat-0g34 | class Solution {\npublic:\n int maximumUniqueSubarray(vector& nums) {\n \n // Sliding Window Approach\n // Untill duplicate elements we keep o | Ronit-Khatri | NORMAL | 2022-06-16T11:20:52.182043+00:00 | 2022-06-16T11:20:52.182079+00:00 | 163 | false | class Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n \n // Sliding Window Approach\n // Untill duplicate elements we keep on adding and increase our window size\n // hash set -> to keep check for unique elements\n // ans -> storing the maximum sum till now\n ... | 2 | 0 | ['Array', 'Two Pointers', 'C', 'Sliding Window'] | 0 |
maximum-erasure-value | javascript O(n) | javascript-on-by-apb10016-f6ce | \n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumUniqueSubarray = function(nums) {\n const n = nums.length;\n \n const store = ne | apb10016 | NORMAL | 2022-06-13T03:26:44.593253+00:00 | 2022-06-13T03:26:44.593290+00:00 | 132 | false | ```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumUniqueSubarray = function(nums) {\n const n = nums.length;\n \n const store = new Set();\n \n let max = 0,\n left = 0,\n sum = 0;\n \n for(let i = 0; i < n; i++) {\n while(store.has(nums[i])) {\n ... | 2 | 0 | ['Sliding Window', 'JavaScript'] | 1 |
maximum-erasure-value | C++ Solution (Variable Sliding Window) | c-solution-variable-sliding-window-by-sh-ncdx | Solution-->\n\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n// Tried acquire ->store and release\n unordered_ma | shubhaamtiwary_01 | NORMAL | 2022-06-12T20:40:40.683025+00:00 | 2022-06-12T20:40:40.683073+00:00 | 51 | false | Solution-->\n```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n// Tried acquire ->store and release\n unordered_map<int,int> map;\n int i=0;\n int j=0;\n int ans=0;\n int sum=0;\n int count=0;\n while(j<nums.size()){\n// ... | 2 | 0 | ['C', 'Sliding Window'] | 0 |
maximum-erasure-value | Rust - Sliding Window | rust-sliding-window-by-idiotleon-rox4 | Solution - github\n\nProblem List\n#SlidingWindow - github\n#Subarray - github\n\n\nuse std::collections::HashSet;\n/// @author: Leon\n/// https://leetcode.com/ | idiotleon | NORMAL | 2022-06-12T18:49:39.121804+00:00 | 2022-06-12T19:47:25.386280+00:00 | 69 | false | Solution - [github](https://github.com/An7One/lc_soln_rust_leon/tree/main/src/leetcode/lvl2/lc1695)\n\n<b>Problem List</b>\n#SlidingWindow - [github](https://github.com/An7One/leetcode-problems-by-tag-an7one/tree/main/txt/by_technique/n_pointers/by_pointer_amount/2_pointers/sliding_window)\n#Subarray - [github](https:/... | 2 | 0 | ['Sliding Window', 'Rust'] | 0 |
maximum-erasure-value | This problem is same as Longest Substring Without Repeating Characters (Leetcode Problem No 3) | this-problem-is-same-as-longest-substrin-fi6e | ```\n int maximumUniqueSubarray(vector& nums) {\n int i=0;\n int j=0;\n int sum=0;\n int ans = INT_MIN;\n map mp;\n wh | noErrors | NORMAL | 2022-06-12T17:07:30.299388+00:00 | 2022-06-12T17:07:30.299432+00:00 | 73 | false | ```\n int maximumUniqueSubarray(vector<int>& nums) {\n int i=0;\n int j=0;\n int sum=0;\n int ans = INT_MIN;\n map<int,int> mp;\n while(j<nums.size())\n {\n mp[nums[j]]++;\n sum+=nums[j];\n \n if(mp.size()==j-i+1)\n ... | 2 | 0 | ['C', 'Sliding Window'] | 0 |
maximum-erasure-value | Simple two pointers code ,[O(n) time and memory complexity ] | simple-two-pointers-code-on-time-and-mem-n66w | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int frq[10005]={0};\n int l=0,r=0,mx=0,cur_sum=0;\n while | ma7moud7amdy | NORMAL | 2022-06-12T15:41:56.060900+00:00 | 2022-06-12T15:41:56.060943+00:00 | 28 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int frq[10005]={0};\n int l=0,r=0,mx=0,cur_sum=0;\n while(l<nums.size()){\n while(r<nums.size()&&!frq[nums[r]]){\n cur_sum+=nums[r];\n ++frq[nums[r++]];\n }\n ... | 2 | 0 | ['Two Pointers'] | 0 |
maximum-erasure-value | Simple java solution | simple-java-solution-by-siddhant_1602-v7l1 | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] n) {\n int i=0,j=0,s=0,p=0,k=n.length;\n Set nm=new HashSet<>();\n while( | Siddhant_1602 | NORMAL | 2022-06-12T14:54:17.492273+00:00 | 2022-06-12T15:02:01.847968+00:00 | 553 | false | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] n) {\n int i=0,j=0,s=0,p=0,k=n.length;\n Set<Integer> nm=new HashSet<>();\n while(i<k&&j<k)\n {\n if(!nm.contains(n[j]))\n {\n s+=n[j];\n p=Math.max(p,s);\n nm... | 2 | 0 | ['Sliding Window', 'Java'] | 0 |
maximum-erasure-value | ✔ C++ ‖ Sliding Window Solution | c-sliding-window-solution-by-_aditya_heg-xixf | Intuition:-\n->We have to find distinct subarray with largest sum\n-> Since we have to find largest sum distinct subarray, I have used unordered map to get uniq | _Aditya_Hegde_ | NORMAL | 2022-06-12T14:12:42.442348+00:00 | 2022-06-12T16:35:46.276193+00:00 | 193 | false | **Intuition:-**\n**->We have to find distinct subarray with largest sum**\n**->** Since we have to find largest sum distinct subarray, I have used unordered map to get unique elements.\n**->** Initially map will be empty and whenever we are traversing we go on adding elements.\n**->** Whenever we find by adding next va... | 2 | 0 | ['C', 'Sliding Window', 'C++'] | 1 |
maximum-erasure-value | Java/JavaScript/Python Beginner friendly Solutions | javajavascriptpython-beginner-friendly-s-mvs3 | Java\n\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n Set<Integer> set = new HashSet<>();\n int i = 0, j = 0, sum = 0, ma | HimanshuBhoir | NORMAL | 2022-06-12T13:57:32.107960+00:00 | 2022-06-12T13:57:32.108004+00:00 | 322 | false | **Java**\n```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n Set<Integer> set = new HashSet<>();\n int i = 0, j = 0, sum = 0, max = 0;\n while(i < nums.length && j < nums.length){\n if(!set.contains(nums[j])){\n set.add(nums[j]);\n s... | 2 | 0 | ['Python', 'Java', 'JavaScript'] | 0 |
maximum-erasure-value | Observation: This ques is same as Longest substring without repeating characters! | observation-this-ques-is-same-as-longest-2tay | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int l=0, r=0, n = nums.size();\n \n unordered_set<int> s; | arpithiside | NORMAL | 2022-06-12T10:06:42.098870+00:00 | 2022-06-12T10:06:42.098917+00:00 | 61 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int l=0, r=0, n = nums.size();\n \n unordered_set<int> s;\n int sum=0, res=0;\n \n while(r<n) {\n if(s.count(nums[r]) == 0) {\n sum += nums[r];\n res = ... | 2 | 0 | ['Sliding Window'] | 0 |
maximum-erasure-value | O(n) CPP Easy Solution | on-cpp-easy-solution-by-abhishek23a-sp9y | ```\n\nint maximumUniqueSubarray(vector& nums) {\n unordered_setst;\n int n=nums.size();\n vectorprefix_sum(n);\n prefix_sum[0]=nums | abhishek23a | NORMAL | 2022-06-12T10:04:13.458793+00:00 | 2022-06-12T10:04:13.458842+00:00 | 40 | false | ```\n\nint maximumUniqueSubarray(vector<int>& nums) {\n unordered_set<int>st;\n int n=nums.size();\n vector<int>prefix_sum(n);\n prefix_sum[0]=nums[0];\n for(int i=1;i<n;i++){\n prefix_sum[i]=prefix_sum[i-1]+nums[i];\n }\n int i=0, max_sum=0;\n for(int ... | 2 | 0 | ['Prefix Sum'] | 0 |
maximum-erasure-value | C++ | O(N) | Two pointers & Hash-Set | c-on-two-pointers-hash-set-by-raiaankur1-z6ps | \n\n\nint maximumUniqueSubarray(vector<int>& nums) {\n int ret=0, sum=0, i=0, n=nums.size();\n vector<bool> found(10001,false);\n for(int j | raiaankur1 | NORMAL | 2022-06-12T09:43:14.293017+00:00 | 2022-06-12T09:43:14.293062+00:00 | 35 | false | \n\n```\nint maximumUniqueSubarray(vector<int>& nums) {\n int ret=0, sum=0, i=0, n=nums.size();\n vector<bool> found(10001,false);\n for(int j=0; j<n; j++){\n sum += nums[j];\n ... | 2 | 1 | ['Two Pointers'] | 0 |
maximum-erasure-value | C++ | O(n) | 98.7% faster | Easy to understand | Clean code | c-on-987-faster-easy-to-understand-clean-8156 | Just maintain sum of all the elements between start and end of the subArray - 2 pointers Approach\n\nclass Solution {\npublic:\n\n int getMax(vector &nums){\ | VAIBHAV_SHORAN | NORMAL | 2022-06-12T08:04:30.060127+00:00 | 2022-06-12T08:17:35.405394+00:00 | 102 | false | **Just maintain sum of all the elements between start and end of the subArray - 2 pointers Approach**\n\nclass Solution {\npublic:\n\n int getMax(vector<int> &nums){\n int maxi = nums[0];\n for(int i=1; i<nums.size(); i++){\n if(nums[i] > maxi){\n maxi = nums[i];\n ... | 2 | 0 | [] | 0 |
maximum-erasure-value | Java Solution || Faster than 96% | java-solution-faster-than-96-by-samarth-q3mqf | \nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n int res=0, sum=0;\n boolean[] seen = new boolean[10001];\n for (in | Samarth-Khatri | NORMAL | 2022-06-12T08:03:32.480663+00:00 | 2022-06-12T08:03:32.480705+00:00 | 37 | false | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n int res=0, sum=0;\n boolean[] seen = new boolean[10001];\n for (int i=0,j=0;i<nums.length;++i){\n while(seen[nums[i]]){\n seen[nums[j]] = false;\n sum -= nums[j++];\n }\n ... | 2 | 0 | ['Java'] | 0 |
maximum-erasure-value | C# Solution | HashSet | Sliding Window | O(N) | c-solution-hashset-sliding-window-on-by-px0lt | \npublic int MaximumUniqueSubarray(int[] nums) {\n int start = 0;\n int end = 0;\n int maxScore = 0;\n int score = 0;\n var h | anshulgarg904 | NORMAL | 2022-06-12T06:41:28.443354+00:00 | 2022-06-12T06:42:20.032997+00:00 | 100 | false | ```\npublic int MaximumUniqueSubarray(int[] nums) {\n int start = 0;\n int end = 0;\n int maxScore = 0;\n int score = 0;\n var hashSet = new HashSet<int>();\n \n while(end < nums.Length){\n if(hashSet.Contains(nums[end])){\n score = score-nums[s... | 2 | 0 | ['C', 'Sliding Window', 'C#'] | 0 |
maximum-erasure-value | EASY AND UNDERSTANDABLE C++ CODE | easy-and-understandable-c-code-by-nayang-dyk5 | \nclass Solution {\npublic:\n int lengthOfLongestSubarray(vector<int>& s) \n {\n int i = 0, j = 0;\n int sum=0;\n int maxsum = 0; | nayangupta143 | NORMAL | 2022-06-12T06:41:18.144422+00:00 | 2022-06-12T06:41:18.144482+00:00 | 271 | false | ```\nclass Solution {\npublic:\n int lengthOfLongestSubarray(vector<int>& s) \n {\n int i = 0, j = 0;\n int sum=0;\n int maxsum = 0; \n unordered_map<int,int> mp;\n \n while(j < s.size())\n {\t\n mp[s[j]]++;\n sum=sum+s[j];\n \n ... | 2 | 0 | ['C', 'Sliding Window'] | 0 |
maximum-erasure-value | Maximum Erasure Value - ✅C++ | Python | O(N) | Easy Solution | maximum-erasure-value-c-python-on-easy-s-xc8d | Maximum Erasure Value\nThis problem is very much similar to Longest Substring Without Repeating Characters. \nI recommend to solve this problem before trying Ma | harish2503 | NORMAL | 2022-06-12T06:38:00.880722+00:00 | 2022-07-06T04:42:37.942084+00:00 | 345 | false | # Maximum Erasure Value\nThis problem is very much similar to Longest Substring Without Repeating Characters. \nI recommend to solve this problem before trying Maximum Erasure Value - https://leetcode.com/problems/longest-substring-without-repeating-characters \n\n**Example:**\n**nums = [4,2,4,5,6]**\nThe output should... | 2 | 0 | ['C', 'Sliding Window', 'Python', 'C++'] | 1 |
maximum-erasure-value | C++ || Easy approach || Sliding Window & Hashmap | c-easy-approach-sliding-window-hashmap-b-qf8u | simply using sliding window technique with map and meanwhile calculatin the sum \nif anywhere found repeated element the slide the window ahead.\n\nupvote if it | Md_Rafiq | NORMAL | 2022-06-12T06:35:09.499526+00:00 | 2022-06-12T06:41:08.538744+00:00 | 35 | false | simply using sliding window technique with map and meanwhile calculatin the sum \nif anywhere found repeated element the slide the window ahead.\n\nupvote if it helped you.\n```\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int ,int> map;\n int i=0,j=0;\n int sum=0;\n int ... | 2 | 0 | ['Two Pointers', 'C', 'Sliding Window'] | 0 |
maximum-erasure-value | Java || HashMap || O(N) solution || Single Iteration | java-hashmap-on-solution-single-iteratio-vdrl | \nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n HashMap<Integer,Integer>loc=new HashMap<>(); //stores the index of last occurran | shiv_am | NORMAL | 2022-06-12T05:42:42.447990+00:00 | 2022-06-12T05:42:42.448033+00:00 | 354 | false | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n HashMap<Integer,Integer>loc=new HashMap<>(); //stores the index of last occurrance of the number\n HashMap<Integer,Integer>sum=new HashMap<>(); //stores the prefix sum\n int ans=0;//stores the final answer\n int tota... | 2 | 0 | ['Prefix Sum', 'Java'] | 0 |
maximum-erasure-value | Sliding Window || Set || Clean Code || JAVA | sliding-window-set-clean-code-java-by-ut-ibjx | Time Complexity (Worst) : O(N x K) where K is the range from the starting till we find that duplicate.\n\n\nclass Solution {\n public int maximumUniqueSubar | UttamKumar22 | NORMAL | 2022-06-12T05:35:55.244947+00:00 | 2022-06-12T05:38:19.005041+00:00 | 44 | false | Time Complexity (Worst) : O(N x K) where K is the range from the starting till we find that duplicate.\n\n```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n \n int start = 0, end = 0, sum = 0, max = 0;\n HashSet<Integer> set = new HashSet<>();\n \n while(end ... | 2 | 0 | ['Sliding Window', 'Java'] | 0 |
maximum-erasure-value | ✅C++ | Easy Sliding Window Approach!! | c-easy-sliding-window-approach-by-shm_47-zkgp | This question is similar to: https://leetcode.com/problems/longest-substring-without-repeating-characters/\n\nCode with comments:\n\nclass Solution {\npublic:\n | shm_47 | NORMAL | 2022-06-12T05:22:25.682748+00:00 | 2022-06-12T05:27:12.386029+00:00 | 259 | false | This question is similar to: https://leetcode.com/problems/longest-substring-without-repeating-characters/\n\n**Code with comments:**\n```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n //finding subarray(with unique elements) with maximum score\n int score = -1;\n ... | 2 | 0 | ['Two Pointers', 'C', 'Sliding Window'] | 0 |
maximum-erasure-value | Short, Simple and concise | C++ | short-simple-and-concise-c-by-tusharbhar-qas0 | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int, int> m;\n \n int i = 0, j = 0, sum = 0 | TusharBhart | NORMAL | 2022-06-12T04:16:31.321799+00:00 | 2022-06-12T04:16:31.321839+00:00 | 128 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n unordered_map<int, int> m;\n \n int i = 0, j = 0, sum = 0, ans = 0;\n while(j < nums.size()) {\n m[nums[j]]++;\n sum += nums[j];\n \n if(m.size() == j - i + 1) ans... | 2 | 0 | ['Two Pointers', 'C', 'Sliding Window'] | 0 |
maximum-erasure-value | C++ || sliding window || simple code | c-sliding-window-simple-code-by-priyansh-y1w4 | class Solution {\npublic:\n\n int maximumUniqueSubarray(vector& nums) {\nint n=nums.size();\n unordered_mapmp;\n int sum=0;\n int mx=0;\ | priyanshu2001 | NORMAL | 2022-06-12T03:29:46.380725+00:00 | 2022-06-12T03:29:46.380753+00:00 | 169 | false | class Solution {\npublic:\n\n int maximumUniqueSubarray(vector<int>& nums) {\nint n=nums.size();\n unordered_map<int,int>mp;\n int sum=0;\n int mx=0;\n int i=0;\n int j=0;\n while(j<n)\n {\n sum+=nums[j];\n mp[nums[j]]++;\n \n ... | 2 | 0 | ['C'] | 0 |
maximum-erasure-value | Javascript ||Time: 92 ms (100.00%), Space: 52.6 MB (95.00%) | javascript-time-92-ms-10000-space-526-mb-gps3 | \n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumUniqueSubarray = function(nums) {\n let map = new Int8Array(10001), high = 0, sum = 0; | gino23odar | NORMAL | 2022-06-12T02:41:01.728903+00:00 | 2022-06-12T02:41:01.728925+00:00 | 152 | false | ```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumUniqueSubarray = function(nums) {\n let map = new Int8Array(10001), high = 0, sum = 0;\n \n for(let left = 0, right = 0; right < nums.length; right++){\n //map the numbers and add to the total sum\n map[nums[right]]++;\n ... | 2 | 0 | ['Sliding Window', 'JavaScript'] | 0 |
maximum-erasure-value | Python | sliding window (two pointers) + hash set | with comments | python-sliding-window-two-pointers-hash-aoc8j | How I approach this problem:\n1. Use a hash set to track the numbers in the current window. \n2. Use curSum to track the sum of the number in the current window | BoluoUp | NORMAL | 2022-06-12T00:55:09.993195+00:00 | 2022-06-12T00:55:09.993228+00:00 | 185 | false | How I approach this problem:\n1. Use a hash set to track the numbers in the current ```window```. \n2. Use ```curSum``` to track the sum of the number in the current window.\n3. Use two pointers ```l``` and ```r``` to expand and shrink the sliding window.\n4. Move ```r```. When encounter duplicate numbers in the window... | 2 | 0 | ['Two Pointers', 'Sliding Window', 'Python'] | 0 |
maximum-erasure-value | Maximum Erasure Value | Java | Sliding Window | HashMap | maximum-erasure-value-java-sliding-windo-hohu | public int maximumUniqueSubarray(int[] nums) {\n \n int i=0;\n int j=0;\n int max=0;\n int sum=0;\n HashMap map = new HashMap | njyotiprakash189 | NORMAL | 2022-06-10T14:43:41.376898+00:00 | 2022-06-10T14:43:41.376931+00:00 | 131 | false | public int maximumUniqueSubarray(int[] nums) {\n \n int i=0;\n int j=0;\n int max=0;\n int sum=0;\n HashMap<Integer, Integer> map = new HashMap<>();\n while(j<nums.length)\n {\n map.put(nums[j], map.getOrDefault(nums[j],0)+1);\n sum +=nums[j];\n ... | 2 | 0 | ['Sliding Window', 'Java'] | 0 |
maximum-erasure-value | Sliding window with unordered_map || c++ || faster | sliding-window-with-unordered_map-c-fast-8vao | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n \n unordered_map<int,int> mp;\n int n = nums.size();\n | binayKr | NORMAL | 2022-02-13T09:17:26.257891+00:00 | 2022-02-13T09:17:26.257942+00:00 | 92 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n \n unordered_map<int,int> mp;\n int n = nums.size();\n int maxi = INT_MIN, sum=0, i =0, j=0;\n while(i<n)\n {\n if(mp.count(nums[i]) and mp[nums[i]]>= j) \n {\n s... | 2 | 0 | ['C', 'Sliding Window'] | 0 |
maximum-erasure-value | LinkedIn | Best Solution | Sliding Window | Readable code | C++ | O(N) | linkedin-best-solution-sliding-window-re-c9s6 | \nint maximumUniqueSubarray(vector<int>& nums) {\n int N = nums.size(), left = 0, right = 0;\n int currsum = 0, maxsum = 0;\n bool duplicat | executable16 | NORMAL | 2022-02-12T17:47:54.332720+00:00 | 2022-02-12T17:48:21.542444+00:00 | 83 | false | ```\nint maximumUniqueSubarray(vector<int>& nums) {\n int N = nums.size(), left = 0, right = 0;\n int currsum = 0, maxsum = 0;\n bool duplicateExists = false;\n \n unordered_map <int,int> freq;\n \n while(right < N){\n int num = nums[right];\n freq[... | 2 | 0 | ['C', 'Sliding Window'] | 0 |
maximum-erasure-value | Java | Sliding Window | HashMap | java-sliding-window-hashmap-by-user8540k-6gvs | \nclass Solution {\n public int maximumUniqueSubarray(int[] arr) {\n Map<Integer,Integer> mp = new HashMap<>();\n int j = 0;\n int i = 0 | user8540kj | NORMAL | 2021-06-10T11:20:58.418569+00:00 | 2021-06-10T11:20:58.418601+00:00 | 96 | false | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] arr) {\n Map<Integer,Integer> mp = new HashMap<>();\n int j = 0;\n int i = 0;\n int sum = 0;\n int max = Integer.MIN_VALUE;\n while(j < arr.length){\n sum = sum + arr[j];\n //insert into map\n ... | 2 | 0 | [] | 0 |
maximum-erasure-value | JAVA || Clean & Concise & Optimal Code || Sliding Window Approach || 6ms Time || 95% Faster Solution | java-clean-concise-optimal-code-sliding-w4ix5 | \nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n \n int maxSum = 0;\n int[] sum = new int[nums.length + 1];\n | anii_agrawal | NORMAL | 2021-05-31T04:25:07.082145+00:00 | 2021-05-31T04:25:07.082177+00:00 | 146 | false | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n \n int maxSum = 0;\n int[] sum = new int[nums.length + 1];\n int[] index = new int[10001];\n \n for (int i = 0, j = 0; i < nums.length; i++) {\n j = Math.max (j, index[nums[i]]);\n ... | 2 | 1 | ['Sliding Window', 'Java'] | 1 |
maximum-erasure-value | C++| Comments | Clean and small code | 2 pointer | c-comments-clean-and-small-code-2-pointe-bash | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& a) {\n int ans=0;\n \n auto it=a.insert(a.begin(),0); //Make 1-base | Coder_Shubham_24 | NORMAL | 2021-05-29T05:54:50.277267+00:00 | 2021-05-29T05:54:50.277300+00:00 | 97 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& a) {\n int ans=0;\n \n auto it=a.insert(a.begin(),0); //Make 1-based indexing \n \n int st=0, n=a.size()-1, i; //st->is start pointer of each unique window \n \n int vis[10001]={0}; // Maintains l... | 2 | 0 | [] | 1 |
maximum-erasure-value | C# sliding window solution | c-sliding-window-solution-by-newbiecoder-5rpi | time: O(N)\n- space: O(N)\n\n\npublic class Solution {\n public int MaximumUniqueSubarray(int[] nums) {\n \n if(nums == null || nums.Length == | newbiecoder1 | NORMAL | 2021-05-28T16:05:59.570755+00:00 | 2021-05-28T16:05:59.570800+00:00 | 79 | false | - time: O(N)\n- space: O(N)\n\n```\npublic class Solution {\n public int MaximumUniqueSubarray(int[] nums) {\n \n if(nums == null || nums.Length == 0)\n return 0;\n \n Dictionary<int,int> dic = new Dictionary<int,int>();\n int left = 0, right = 0, sum = 0, max = 0, count... | 2 | 0 | [] | 0 |
maximum-elegance-of-a-k-length-subsequence | [Java/C++/Python] Sort by Profit | javacpython-sort-by-profit-by-lee215-muyg | Intuition\nSort items by decresed profiti,\nand we take k first items.\nThis is biggest total_profit we can have.\n\n\n# Explanation\nContinue to iterate the re | lee215 | NORMAL | 2023-08-06T04:04:37.927859+00:00 | 2023-08-06T04:18:20.394311+00:00 | 3,368 | false | # **Intuition**\nSort `items` by decresed `profiti`,\nand we take `k` first items.\nThis is biggest `total_profit` we can have.\n<br>\n\n# **Explanation**\nContinue to iterate the remaining `n - k` items.\nWe can try to take them,\nif this is a new `category` and not in `seen` set.\n\nBut we already have `k` items,\nso... | 98 | 0 | ['C', 'Python', 'Java'] | 18 |
maximum-elegance-of-a-k-length-subsequence | Track Dups | track-dups-by-votrubac-whpi | We sort items by profit, and take first k items.\n\nWe also track how many unique categories cats are there. If we see another item in the existing category, we | votrubac | NORMAL | 2023-08-06T05:25:45.040799+00:00 | 2023-08-06T05:40:08.574492+00:00 | 706 | false | We sort items by profit, and take first `k` items.\n\nWe also track how many unique categories `cats` are there. If we see another item in the existing category, we place it into `dups`.\n\nNow, let\'s see if we can improve our result by considering remaining `n - k` items:\n- If the item category already exists in `ca... | 20 | 0 | ['C'] | 3 |
maximum-elegance-of-a-k-length-subsequence | Greedy C++ & Java | greedy-c-java-by-cpcs-yyvg | Btw, the question is excatly the same as the one I published before.\n\n\nhttps://leetcode.com/discuss/interview-question/3624545/GPL-Challenge-Q1\n\n\n# Intuit | cpcs | NORMAL | 2023-08-06T04:01:13.933051+00:00 | 2023-08-06T04:01:13.933074+00:00 | 1,627 | false | Btw, the question is excatly the same as the one I published before.\n\n\n[https://leetcode.com/discuss/interview-question/3624545/GPL-Challenge-Q1](https://leetcode.com/discuss/interview-question/3624545/GPL-Challenge-Q1)\n\n\n# Intuition\nGreedy algorithm\n\n\n(1) sort the items by the profit (items[.][0]) in non inc... | 19 | 0 | ['C++', 'Java'] | 5 |
maximum-elegance-of-a-k-length-subsequence | Probably the easiest solution. | probably-the-easiest-solution-by-agnishh-dley | Intuition\nThere is an inclination to go towards DP when you hear subsequences. The constraints made me feel it was greedy.\n\n# Approach\nFirst sort the array | agnishh | NORMAL | 2023-08-06T06:40:28.685585+00:00 | 2023-08-06T10:24:46.290273+00:00 | 555 | false | # Intuition\nThere is an inclination to go towards DP when you hear subsequences. The constraints made me feel it was greedy.\n\n# Approach\nFirst sort the array by profits in descending order.\nSimply take first k elements. Since there is a factor of categories in profit calculation, keep a set with all categories. In... | 11 | 0 | ['Greedy', 'Sorting', 'C++'] | 3 |
maximum-elegance-of-a-k-length-subsequence | Python 3 || head vs tail || T/S: 99% / 31% | python-3-head-vs-tail-ts-99-31-by-spauld-p3de | \nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n\n items.sort(reverse = True)\n sm, seenCats, dups = | Spaulding_ | NORMAL | 2023-08-08T18:24:18.512146+00:00 | 2024-06-21T18:06:18.161515+00:00 | 283 | false | ```\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n\n items.sort(reverse = True)\n sm, seenCats, dups = 0, set(), deque()\n\n for headPrf, headCat in items[:k]:\n \n sm+= headPrf\n\n if headCat in seenCats: dups.append(h... | 8 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | [Python3] Greedy | python3-greedy-by-awice-5b4n | Intuition\n\nSay an item is golden if it has the highest profit in its category.\n\nSuppose we use $C$ categories in our selection. It consists of the most pro | awice | NORMAL | 2023-08-06T14:35:03.804723+00:00 | 2023-08-06T14:35:03.804743+00:00 | 249 | false | **Intuition**\n\nSay an item is *golden* if it has the highest profit in its category.\n\nSuppose we use $C$ categories in our selection. It consists of the most profitable $C$ golden items, and the rest of the items are chosen to be the ones with the highest profit.\n\n**Algorithm**\n\nSort `items` decreasing by prof... | 8 | 0 | ['Python3'] | 1 |
maximum-elegance-of-a-k-length-subsequence | C++ Easy Solution || Best Approach ||✅✅ | c-easy-solution-best-approach-by-abhi_pa-dhdy | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | abhi_pandit_18 | NORMAL | 2023-08-06T04:04:37.082117+00:00 | 2023-08-06T04:04:37.082138+00:00 | 540 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 6 | 3 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Greedy Approach | greedy-approach-by-rahulraturi2002-xgg1 | We want to calculate : total_profit + distinct_categories^2\n\n We sort profit in descending order and take first k profits including duplicate categories\n Wh | rahulraturi2002 | NORMAL | 2023-08-06T08:53:30.707699+00:00 | 2023-08-06T08:53:30.707746+00:00 | 303 | false | We want to calculate : **total_profit + distinct_categories^2**\n\n* We sort profit in descending order and take first k profits including duplicate categories\n* When we reach first k items , now we can maximazie distinct_categories by adding them into set and removing lowest duplicate items from set\n\n```\n\n#defin... | 5 | 0 | ['Greedy', 'C'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ Greedy || sorting + map + priority Queue | c-greedy-sorting-map-priority-queue-by-a-5qp8 | \n# Code\n\nclass Solution {\npublic: \n long long findMaximumElegance(vector<vector<int>>&items, int k) {\n sort(items.rbegin(),items.rend());\n | avadhut7969 | NORMAL | 2023-09-01T14:20:53.757758+00:00 | 2023-09-01T14:20:53.757787+00:00 | 62 | false | \n# Code\n```\nclass Solution {\npublic: \n long long findMaximumElegance(vector<vector<int>>&items, int k) {\n sort(items.rbegin(),items.rend());\n long long sum=0;\n map<int,multiset<int>>st;\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n for... | 4 | 0 | ['Hash Table', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Ordered Set', 'C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.