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-size-of-a-set-after-removals | Set + math O(t):n | set-math-t-on-by-blackbrain2009-0f9q | I inspired Tayomide for solution, it pleasantly surprised me.IntuitionApproachComplexity
Time complexity: O(n)
Space complexity: O(n)
Code | blackbrain2009 | NORMAL | 2024-01-07T04:02:00.881639+00:00 | 2025-03-31T20:09:11.492703+00:00 | 97 | false | I inspired [Tayomide](https://leetcode.com/Tayomide/) for [solution](https://leetcode.com/problems/maximum-size-of-a-set-after-removals/solutions/4520968/javascript-set-and-logic-operations/), it pleasantly surprised me.
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!--... | 1 | 0 | ['Math', 'JavaScript'] | 0 |
maximum-size-of-a-set-after-removals | JAVA COMMENTED SOLUTION INTUTIVE PRIORITY QUEUE BASED SOLUTION | java-commented-solution-intutive-priorit-i2r0 | \n\n\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n // Frequency map for nums1 and nums2\n HashMap<Integer, Intege | Sai_Govind_2024 | NORMAL | 2024-01-07T04:01:47.262767+00:00 | 2024-01-07T04:46:45.945498+00:00 | 350 | false | ```\n\n\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n // Frequency map for nums1 and nums2\n HashMap<Integer, Integer> frequencyMap1 = new HashMap<>();\n HashMap<Integer, Integer> frequencyMap2 = new HashMap<>();\n\n // Counting frequency for nums1\n f... | 1 | 0 | ['Hash Table', 'Greedy', 'C', 'Heap (Priority Queue)', 'Java'] | 0 |
maximum-size-of-a-set-after-removals | Super Easy and Fast solution C# | super-easy-and-fast-solution-c-by-bogdan-ub2s | Complexity
Time complexity: O(N)
Space complexity: O(N)
Code | bogdanonline444 | NORMAL | 2025-03-27T12:17:34.640693+00:00 | 2025-03-27T12:17:34.640693+00:00 | 2 | false |
# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```csharp []
public class Solution {
public int MaximumSetSize(int[] nums1, int[] nums2) {
int n = nums1.Length;
HashSe... | 0 | 0 | ['Array', 'Hash Table', 'C#'] | 0 |
maximum-size-of-a-set-after-removals | first one solved | first-one-solved-by-abbass_tabikh-koed | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Abbass_Tabikh | NORMAL | 2025-03-09T14:48:03.461417+00:00 | 2025-03-09T14:48:03.461417+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C#'] | 0 |
maximum-size-of-a-set-after-removals | Easy CPP Solution | easy-cpp-solution-by-rdbhalekar_2907-pdro | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Rdbhalekar_2907 | NORMAL | 2025-03-06T06:30:26.961095+00:00 | 2025-03-06T06:30:26.961095+00:00 | 0 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Easy CPP Solution | easy-cpp-solution-by-rdbhalekar_2907-ntvn | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Rdbhalekar_2907 | NORMAL | 2025-03-06T06:30:25.157019+00:00 | 2025-03-06T06:30:25.157019+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Easy hash table | easy-hash-table-by-minh_hung-kopt | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | minh_hung | NORMAL | 2025-03-05T22:55:12.574947+00:00 | 2025-03-05T22:55:12.574947+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
maximum-size-of-a-set-after-removals | C++ Simple Hash Based Solution With Step-Wise Comments | c-simple-hash-based-solution-with-step-w-dmlg | IntuitionTry removing elems having freq>1 and than target common elements.Common elems remove from both and than later distribute to map which can accomodate it | SJ4u | NORMAL | 2025-02-22T11:18:08.262478+00:00 | 2025-02-22T11:18:08.262478+00:00 | 3 | false | # Intuition
Try removing elems having freq>1 and than target common elements.
Common elems remove from both and than later distribute to map which can accomodate it (i.e. removal has become negative).
# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: ... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Easy solution C++ | easy-solution-c-by-trivedi_anshul-e9f5 | IntuitionA set contains unique entries.1)So, why don't we first remove all the duplicate entries, keeping at least only one entry of that element.Now, if the re | Trivedi_Anshul | NORMAL | 2025-02-21T05:49:27.742455+00:00 | 2025-02-21T05:49:27.742455+00:00 | 2 | false | # Intuition
A set contains unique entries.
1)So, why don't we first remove all the duplicate entries, keeping at least only one entry of that element.
Now, if the required size (n) is achieved, the job is done.
2)Otherwise, we still need to remove elements from the arrays(either from one or from the other or from bot... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | It's a math question | its-a-math-question-by-linda2024-c1kh | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | linda2024 | NORMAL | 2025-02-10T19:56:47.890321+00:00 | 2025-02-10T19:56:47.890321+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time compl... | 0 | 0 | ['C#'] | 0 |
maximum-size-of-a-set-after-removals | Maximum size of a Set After Removals | maximum-size-of-a-set-after-removals-by-b8f39 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Naeem_ABD | NORMAL | 2025-01-13T18:52:32.560521+00:00 | 2025-01-13T18:52:32.560521+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
maximum-size-of-a-set-after-removals | Simple logical thinking | simple-logical-thinking-by-vaibhavt19-fpu2 | IntuitionApproachComplexity
Time complexity: O(n)
Space complexity:O(n)
Code | Vaibhavt19 | NORMAL | 2025-01-04T17:57:03.416459+00:00 | 2025-01-04T17:57:03.416459+00:00 | 6 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Big And Small | big-and-small-by-tonitannoury01-t6bv | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
Code | tonitannoury01 | NORMAL | 2024-12-27T19:49:03.721123+00:00 | 2024-12-27T19:49:03.721123+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```javascript []
/**
* @param {number[]} nums1
*... | 0 | 0 | ['JavaScript'] | 0 |
maximum-size-of-a-set-after-removals | Hash Map Solution CPP 0(n) | hash-map-solution-cpp-0n-by-saga_9-evok | Intuition-> First keep them in hash map respectively, to make search in constant time,
-> Now we will get the common element count and two variable for unique e | saga_9 | NORMAL | 2024-12-24T08:04:20.700670+00:00 | 2024-12-24T08:04:20.700670+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
-> First keep them in hash map respectively, to make search in constant time,
-> Now we will get the common element count and two variable for unique element count from repective array against other array.
# Approach
<!-- Describe your appr... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Hash Map Solution CPP 0(n) | hash-map-solution-cpp-0n-by-saga_9-w5mw | Intuition-> First keep them in hash map respectively, to make search in constant time,
-> Now we will get the common element count and two variable for unique e | saga_9 | NORMAL | 2024-12-24T08:04:18.050172+00:00 | 2024-12-24T08:04:18.050172+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
-> First keep them in hash map respectively, to make search in constant time,
-> Now we will get the common element count and two variable for unique element count from repective array against other array.
# Approach
<!-- Describe your appr... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Using sets, 100% speed | using-sets-100-speed-by-evgenysh-02h5 | \n\n# Code\npython3 []\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n target = len(nums1) // 2\n uni | evgenysh | NORMAL | 2024-10-19T22:50:28.507975+00:00 | 2024-10-19T22:50:28.507992+00:00 | 7 | false | \n\n# Code\n```python3 []\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n target = len(nums1) // 2\n unique1, unique2 = set(nums1), set(nums2)\n ... | 0 | 0 | ['Python3'] | 0 |
maximum-size-of-a-set-after-removals | Using only hashset O(N) | using-only-hashset-on-by-happy_coderr-x637 | Intuition\nTo maximize the set we need to pick most unique elements\n\n# Approach\n1. Get unique elements of num1 in set1 which are not there in set2\n2. Get un | happy_coderr | NORMAL | 2024-10-15T19:16:42.741466+00:00 | 2024-10-15T19:23:10.679931+00:00 | 0 | false | # Intuition\nTo maximize the set we need to pick most unique elements\n\n# Approach\n1. Get unique elements of num1 in set1 which are not there in set2\n2. Get unique elements of num2 in set2 which are not there in set1\n3. Get common elemenets which are available in both set1 and set2\n4. Not we can pick elements from... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | solving this by good approach for beginner easily to understand using set in java script | solving-this-by-good-approach-for-beginn-bw2m | Intuition\nThe function maximumSetSize aims to determine the maximum size of a set formed from two input arrays, nums1 and nums2, with certain constraints. The | adii-the-billionaire | NORMAL | 2024-10-08T14:09:19.932431+00:00 | 2024-10-08T14:09:19.932464+00:00 | 6 | false | # Intuition\nThe function maximumSetSize aims to determine the maximum size of a set formed from two input arrays, nums1 and nums2, with certain constraints. The constraints are based on the number of common elements between the two sets created from the input arrays. The idea is to maximize the size of a new set while... | 0 | 0 | ['JavaScript'] | 1 |
maximum-size-of-a-set-after-removals | Easy Solution using HashSet in Java | easy-solution-using-hashset-in-java-by-k-zlvk | Intuition\n Describe your first thoughts on how to solve this problem. \nWe neet to maximise the size of the final set , so we need unique elements because is r | kakuruhela2511 | NORMAL | 2024-09-24T12:43:43.775592+00:00 | 2024-09-24T12:43:43.775626+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe neet to maximise the size of the final set , so we need unique elements because is repeated elements are there they are added once and will not increase the size of final set.\n\n# Approach\n<!-- Describe your approach to solving the p... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Simple || Straightforward | simple-straightforward-by-abhi5114-51el | 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 | Abhi5114 | NORMAL | 2024-09-09T10:12:59.670257+00:00 | 2024-09-09T10:15:14.191603+00:00 | 0 | 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)$$ --... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Easy Set Solution | easy-set-solution-by-kvivekcodes-hn86 | 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 | kvivekcodes | NORMAL | 2024-08-21T03:42:55.896053+00:00 | 2024-08-21T03:42:55.896085+00:00 | 4 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | HASH SET | hash-set-by-shahsb-brhz | Key Observation\n1) The final answer will not exceed N. Where N = (n/2) + (n/2) (unique elements of nums1 & nums2).\n2) Common items from s1 & s2 would be consi | shahsb | NORMAL | 2024-08-18T09:10:24.024937+00:00 | 2024-08-18T09:28:29.537918+00:00 | 2 | false | # Key Observation\n1) The final answer will not exceed N. Where `N = (n/2) + (n/2)` (unique elements of nums1 & nums2).\n2) Common items from s1 & s2 would be considered only once.\n3) If we have more than `n/2` unique elements in both s1 & s2, we can easily discard them.\n4) Imporatant observation is that we have to r... | 0 | 0 | ['C'] | 0 |
maximum-size-of-a-set-after-removals | Simple Java Set Solution: Beats 89% | simple-java-set-solution-beats-89-by-gav-tywx | Intuition\n Describe your first thoughts on how to solve this problem. \nIn order to maximize set size, you want to remove duplicates first before having to rem | gavgustin3 | NORMAL | 2024-08-15T05:23:56.819532+00:00 | 2024-08-15T05:23:56.819573+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn order to maximize set size, you want to remove duplicates first before having to remove numbers that only appear once.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCalculate how many numbers you need to remov... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Easy CPP Solution | easy-cpp-solution-by-clary_shadowhunters-mo2g | \n\n# Code\n\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) \n {\n set<int>st1(nums1.begin(),nums1.end()); | Clary_ShadowHunters | NORMAL | 2024-08-13T17:59:44.335804+00:00 | 2024-08-13T17:59:44.335847+00:00 | 0 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) \n {\n set<int>st1(nums1.begin(),nums1.end());\n set<int>st2(nums2.begin(),nums2.end());\n int ans1=0;\n int n=nums1.size();\n for (auto it:nums1)\n {\n if (... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Set || Super Simple || C++ | set-super-simple-c-by-lotus18-t5r9 | Code\n\nclass Solution \n{\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) \n {\n set<int> st1, st2;\n int c1=nums1.si | lotus18 | NORMAL | 2024-08-13T17:51:03.537073+00:00 | 2024-08-13T17:51:03.537104+00:00 | 1 | false | # Code\n```\nclass Solution \n{\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) \n {\n set<int> st1, st2;\n int c1=nums1.size()/2, c2=nums2.size()/2;\n for(auto it: nums1)\n {\n if(c1>0 && st1.find(it)!=st1.end()) c1--;\n st1.insert(it);\n ... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | JavaScript Greedy O(n) | javascript-greedy-on-by-lilongxue-n47n | Intuition\nUse the greedy approach. Of course, we should remove duplicates first.\n# Approach\nFor each set:\n 1. Remove all local duplicate elements until hal | lilongxue | NORMAL | 2024-08-01T10:40:15.331528+00:00 | 2024-08-01T10:40:15.331546+00:00 | 5 | false | # Intuition\nUse the greedy approach. Of course, we should remove duplicates first.\n# Approach\nFor each set:\n 1. Remove all local duplicate elements until half are left\n 2. If there are more than half left, remove elements that are also in the other set, until half are left\n 3. If there are still more than half... | 0 | 0 | ['JavaScript'] | 0 |
maximum-size-of-a-set-after-removals | Easy C++ using sets | easy-c-using-sets-by-0xsupra-2gwn | 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# Co | 0xsupra | NORMAL | 2024-07-27T21:22:16.104638+00:00 | 2024-07-27T21:22:16.104659+00:00 | 6 | false | # 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```\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& A, vector<int>& B) {\n int n = A.size();\n\n ... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Beats 100%💯 Easy to understand c++ | beats-100-easy-to-understand-c-by-gokuuu-0jlq | \n\n# Approach\nUse Hashmaps to store freq of both arrays.Add unique elements of both arrays in the set.If space left add duplicate elements:)\n\n# Complexity\n | Gokuuu | NORMAL | 2024-07-19T04:53:12.416105+00:00 | 2024-07-19T04:53:12.416121+00:00 | 3 | false | \n\n# Approach\nUse Hashmaps to store freq of both arrays.Add unique elements of both arrays in the set.If space left add duplicate elements:)\n\n# Complexity\n- Time complexity:\nO(N1+N2)\n\n- Space complexity:\nO(N1+N2)\n\n# Code\n```\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>&... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Easy Java Solution || HashSet | easy-java-solution-hashset-by-mnnit1prak-haeq | 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 | mnnit_prakharg | NORMAL | 2024-07-16T15:26:11.046242+00:00 | 2024-07-16T15:26:11.046278+00:00 | 7 | 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)$$ --... | 0 | 0 | ['Hash Table', 'Greedy', 'Java'] | 0 |
maximum-size-of-a-set-after-removals | [C++] Greedy, Hash Tables | c-greedy-hash-tables-by-amanmehara-n0kx | Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nu | amanmehara | NORMAL | 2024-07-04T02:51:27.885923+00:00 | 2024-07-04T02:51:27.885959+00:00 | 3 | false | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n unordered_set<int> s1, s2, join;\n for (const auto& num : nums1) {\n s1.insert(num... | 0 | 0 | ['Array', 'Hash Table', 'Greedy', 'C++'] | 0 |
maximum-size-of-a-set-after-removals | Simple Java Solution!!! | simple-java-solution-by-shankarreddy1503-6zb4 | 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 | shankarreddy1503 | NORMAL | 2024-06-07T05:40:41.498388+00:00 | 2024-06-07T05:40:41.498416+00:00 | 17 | 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)$$ --... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Finally Got it | finally-got-it-by-brianh27-ljqb | I first wen through each list. We may use greedy since we just need 1 occurence of an item for it to count.\nSo I start with 2 variables.\nThen I went through e | brianh27 | NORMAL | 2024-06-03T04:50:12.592665+00:00 | 2024-06-03T04:50:12.592684+00:00 | 13 | false | I first wen through each list. We may use greedy since we just need 1 occurence of an item for it to count.\nSo I start with 2 variables.\nThen I went through each list to get rid of the numbers that occur more than once in each individual list. This is a guarenteed thinning.\n(Also I stored the occurences of both list... | 0 | 0 | ['Python3'] | 0 |
maximum-size-of-a-set-after-removals | Easy C++ only Maps Solution| TC: O(n) | SC: O(n) | easy-c-only-maps-solution-tc-on-sc-on-by-yvew | Approach\n1. feed all the elements from nums1 to map1 (m1)\n2. feed all the elements from nums2 to map2 (m2)\n3. iterate over the m1 and take unique elements on | the_shridhar | NORMAL | 2024-05-18T14:29:27.678350+00:00 | 2024-05-18T14:29:27.678389+00:00 | 9 | false | # Approach\n1. feed all the elements from `nums1` to `map1 (m1)`\n2. feed all the elements from `nums2` to `map2 (m2)`\n3. iterate over the `m1` and take unique elements only, while iterating your are taking only `<=n/2` elements and delete them from map if taken. Maintain a count how much elements you took (lets say `... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Simple Java Solution | simple-java-solution-by-sakshikishore-o3di | Code\n\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n HashMap<Integer,Integer> h1=new HashMap<Integer,Integer>();\n | sakshikishore | NORMAL | 2024-05-17T06:36:19.783087+00:00 | 2024-05-17T06:36:19.783116+00:00 | 9 | false | # Code\n```\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n HashMap<Integer,Integer> h1=new HashMap<Integer,Integer>();\n HashMap<Integer,Integer> h2=new HashMap<Integer,Integer>();\n int count1=0,count2=0;\n for(int i=0;i<nums1.length;i++)\n {\n ... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Done 🎯|| C++ ✅ | done-c-by-ajitpal0821-uu83 | Intuition\n Describe your first thoughts on how to solve this problem. \n- Find unique in arr1\n- Find common in both\n- Find unique in arr2\n- Common in both b | ajitpal0821 | NORMAL | 2024-05-09T11:41:18.057763+00:00 | 2024-05-09T11:41:18.057794+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Find unique in arr1\n- Find common in both\n- Find unique in arr2\n- Common in both but not repeated\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity... | 0 | 0 | ['Array', 'Hash Table', 'Greedy', 'C++'] | 0 |
maximum-size-of-a-set-after-removals | C++ maps | c-maps-by-user5976fh-fpor | \nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> m1, m2;\n for (int i = 0; | user5976fh | NORMAL | 2024-05-08T03:38:32.719442+00:00 | 2024-05-08T03:38:32.719510+00:00 | 0 | false | ```\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> m1, m2;\n for (int i = 0; i < nums1.size(); ++i)\n ++m1[nums1[i]], ++m2[nums2[i]];\n int n1 = nums1.size() / 2, n2 = n1;\n for (auto& [f, s] : m1) n1 -= s - 1... | 0 | 0 | [] | 0 |
maximum-size-of-a-set-after-removals | Simple | simple-by-sdg9670-ibov | 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 | sdg9670 | NORMAL | 2024-04-29T13:13:57.348845+00:00 | 2024-04-29T13:14:40.618372+00:00 | 1 | 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(2n)$$\n<!-- Add your space complexity her... | 0 | 0 | ['TypeScript'] | 0 |
maximum-size-of-a-set-after-removals | 3 Set solution | 3-set-solution-by-sanyamgoyal401-jh38 | Code\n\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n set<int> s1;\n | SanyamGoyal401 | NORMAL | 2024-04-19T17:47:18.619481+00:00 | 2024-04-19T17:47:18.619497+00:00 | 1 | false | # Code\n```\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n set<int> s1;\n set<int> s2;\n set<int> s3;\n for(int i=0; i<n; i++){\n s1.insert(nums1[i]);\n s2.insert(nums2[i]);\n }\n\n ... | 0 | 0 | ['Ordered Set', 'C++'] | 0 |
maximum-size-of-a-set-after-removals | One Liner Easy Solution || Python3 | one-liner-easy-solution-python3-by-yangz-mmrl | One Liner Very Easy Solution\n\n\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n return min(len(set(nums1 + | YangZen09 | NORMAL | 2024-04-09T21:14:48.200742+00:00 | 2024-04-09T21:14:48.200772+00:00 | 7 | false | *One Liner Very Easy Solution*\n\n```\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n return min(len(set(nums1 + nums2)), min(len(set(nums1)), len(nums1) // 2) + min(len(set(nums2)), len(nums2) // 2))\n``` | 0 | 0 | ['Math', 'Ordered Set', 'Python3'] | 0 |
maximum-size-of-a-set-after-removals | ✅🔥Easy & simple C++ solution with line by line explanation🔥✅ | easy-simple-c-solution-with-line-by-line-lgwf | Intuition\nNeed to remove n/2 elements from both nums1 and nums2 such that when we combine both then the elements will be maximum.\n\n---\n\n# Approach\n- First | Anshmishra | NORMAL | 2024-03-15T16:37:52.505317+00:00 | 2024-03-15T16:37:52.505350+00:00 | 20 | false | # Intuition\nNeed to remove n/2 elements from both nums1 and nums2 such that when we combine both then the elements will be maximum.\n\n---\n\n# Approach\n- First make a set and store the elements of num1 in the set and take its size.\n- Then clear that set and perform same thing with nums2.\n- Then again clear the set... | 0 | 0 | ['Array', 'Hash Table', 'Greedy', 'C', 'C++'] | 0 |
maximum-size-of-a-set-after-removals | scala solution | scala-solution-by-vititov-rfzh | \nobject Solution {\n def maximumSetSize(nums1: Array[Int], nums2: Array[Int]): Int = {\n val (set1,set2,n) = (nums1.to(Set), nums2.to(Set),nums1.size)\n | vititov | NORMAL | 2024-03-10T15:23:29.868826+00:00 | 2024-03-10T15:36:37.288149+00:00 | 2 | false | ```\nobject Solution {\n def maximumSetSize(nums1: Array[Int], nums2: Array[Int]): Int = {\n val (set1,set2,n) = (nums1.to(Set), nums2.to(Set),nums1.size)\n val both = set1.count(set2.contains(_))\n ((set1.size - both).min(n>>1) + (set2.size - both).min(n>>1) + both) min n\n }\n}}``` | 0 | 0 | ['Scala'] | 0 |
maximum-size-of-a-set-after-removals | C++ Solution | c-solution-by-rattanankit2004-f9yp | Intuition\n Describe your first thoughts on how to solve this problem. \nUsing Sets\n# Approach\n Describe your approach to solving the problem. \n\n# Complexit | rattanankit2004 | NORMAL | 2024-03-10T04:42:24.942712+00:00 | 2024-03-10T04:42:24.942745+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing Sets\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. $... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Greedy | Beats 81% | Using 2 Hash Tables | greedy-beats-81-using-2-hash-tables-by-d-obvt | Submission Screenshot\n\n\n\n\n# Code\ncpp\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<i | darshdattu | NORMAL | 2024-03-09T05:57:39.631437+00:00 | 2024-03-09T05:57:39.631467+00:00 | 9 | false | # Submission Screenshot\n\n\n\n\n# Code\n```cpp\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> mp1;\n unordered_map<int, ... | 0 | 0 | ['Array', 'Hash Table', 'Greedy', 'C++'] | 0 |
maximum-size-of-a-set-after-removals | MaximumSetSize | maximumsetsize-by-santhosh106-gl5s | Intuition\nThink of time Complexity while wirte the code. \n\n# Approach\nUse Greedy Approach to solve the problem.\n# Complexity\n- Time complexity:\nO(n)\n\n- | santhosh106 | NORMAL | 2024-02-25T09:57:14.344615+00:00 | 2024-02-25T09:57:14.344646+00:00 | 5 | false | # Intuition\nThink of time Complexity while wirte the code. \n\n# Approach\nUse Greedy Approach to solve the problem.\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n# Code\n```\n/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maximumSetSize = function (n... | 0 | 0 | ['JavaScript'] | 0 |
maximum-size-of-a-set-after-removals | 👍Runtime 851 ms Beats 100.00% of users with Scala | runtime-851-ms-beats-10000-of-users-with-rpxb | Code\n\nimport scala.collection.mutable.HashSet\n\nobject Solution {\n def maximumSetSize(nums1: Array[Int], nums2: Array[Int]): Int = {\n val set1 = | pvt2024 | NORMAL | 2024-02-25T07:24:57.255757+00:00 | 2024-02-25T07:24:57.255798+00:00 | 6 | false | # Code\n```\nimport scala.collection.mutable.HashSet\n\nobject Solution {\n def maximumSetSize(nums1: Array[Int], nums2: Array[Int]): Int = {\n val set1 = HashSet[Int]()\n val set2 = HashSet[Int]()\n val set3 = HashSet[Int]()\n \n nums1.foreach(x => {\n set1.add(x)\n ... | 0 | 0 | ['Scala'] | 0 |
maximum-size-of-a-set-after-removals | Java | Simplistic Set | java-simplistic-set-by-baljitdhanjal-dyy5 | \n\n# Code\n\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n Set<Integer> sA = Arrays.stream(nums1).boxed().collect(Collec | baljitdhanjal | NORMAL | 2024-02-22T20:18:11.055267+00:00 | 2024-02-22T20:18:11.055303+00:00 | 14 | false | \n\n# Code\n```\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n Set<Integer> sA = Arrays.stream(nums1).boxed().collect(Collectors.toCollection(HashSet::new));\n Set<Integer> sB = Arrays.stream(nums2).boxed().collect(Collectors.toCollection(HashSet::new));\n\n int size... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Easy Java | easy-java-by-lakshyasaharan1997-2dl0 | Code\n\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) { \n Map<Integer,Integer> mp1 = new HashMap<>(); \n | lakshyasaharan1997 | NORMAL | 2024-02-20T18:36:55.049098+00:00 | 2024-02-20T18:36:55.049135+00:00 | 16 | false | # Code\n```\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) { \n Map<Integer,Integer> mp1 = new HashMap<>(); \n Map<Integer,Integer> mp2 = new HashMap<>();\n for(int i=0; i<nums1.length; i++){\n if(!mp1.containsKey(nums1[i])){\n ... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Set || Beat 100% || C++ | set-beat-100-c-by-jacklee13520-6ze3 | \nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) \n {\n unordered_set<int> s1,s2;\n for(auto n:nums1 | jacklee13520 | NORMAL | 2024-02-20T14:24:45.647789+00:00 | 2024-02-20T14:24:45.647815+00:00 | 2 | false | ```\nclass Solution {\npublic:\n int maximumSetSize(vector<int>& nums1, vector<int>& nums2) \n {\n unordered_set<int> s1,s2;\n for(auto n:nums1)\n {\n s1.insert(n);\n }\n for(auto n:nums2)\n {\n s2.insert(n);\n }\n \n // count th... | 0 | 0 | [] | 0 |
maximum-size-of-a-set-after-removals | 🚩 1-liner ^^ | 1-liner-by-andrii_khlevniuk-kbd8 | \n\n\ndef maximumSetSize(self, x, y):\n\treturn min(len(set(x+y)), min(len(set(x)), len(x)//2) + min(len(set(y)), len(y)//2))\n | andrii_khlevniuk | NORMAL | 2024-02-20T13:19:31.628729+00:00 | 2024-02-20T16:58:01.209651+00:00 | 46 | false | \n\n```\ndef maximumSetSize(self, x, y):\n\treturn min(len(set(x+y)), min(len(set(x)), len(x)//2) + min(len(set(y)), len(y)//2))\n``` | 0 | 0 | ['Python', 'Python3'] | 0 |
maximum-size-of-a-set-after-removals | Beginners friendly | beginners-friendly-by-magagical_star-zp3h | 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 | Magagical_star | NORMAL | 2024-02-17T13:46:33.137687+00:00 | 2024-02-17T13:46:33.137732+00:00 | 11 | 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)$$ --... | 0 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
maximum-size-of-a-set-after-removals | Pythonic Mathematical Solution :) | pythonic-mathematical-solution-by-elucid-yekr | Intuition\n\nThe first intuition that came to mind when solving this problem was to determine the unique contribution of each list to the length of the maximum | elucidativemind | NORMAL | 2024-02-15T13:15:23.111097+00:00 | 2024-02-15T13:15:23.111132+00:00 | 35 | false | # Intuition\n\nThe first intuition that came to mind when solving this problem was to determine the unique contribution of each list to the length of the maximum set. By finding the intersecting elements among the lists and converting each list into a hash set, we can identify the unique contribution of each list.\n\n#... | 0 | 0 | ['Math', 'Python'] | 0 |
maximum-size-of-a-set-after-removals | BEAT 96.42% | Shortest, Easiest & Well Explained | To the Point & Beginners Friendly Approach(❤️ω❤️) | beat-9642-shortest-easiest-well-explaine-642g | \n\n# Welcome to My Coding Family\u30FE(\u2267 \u25BD \u2266)\u309D\nThis is my shortest, easiest & to the point approach. This solution mainly aims for purely | Nitansh_Koshta | NORMAL | 2024-02-15T12:25:21.645116+00:00 | 2024-02-15T12:25:21.645143+00:00 | 8 | false | \n\n# Welcome to My Coding Family\u30FE(\u2267 \u25BD \u2266)\u309D\n*This is my shortest, easiest & to the point approach. This solution mainly aims for purely beginners so if you\'re new here th... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | Easy To Understand Java Code | easy-to-understand-java-code-by-harshitm-etpu | 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 | harshitmittal8090 | NORMAL | 2024-02-11T14:07:14.617133+00:00 | 2024-02-11T14:07:14.617161+00:00 | 24 | 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 O(n)\n\n- Space complexity:\n O(n)\n\n# Code\n```\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2){\n\... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | [C++] a method using set | c-a-method-using-set-by-hirofumitsuda-leqy | Intuition\n Describe your first thoughts on how to solve this problem. \nTake components in the following way:\n- take components included either of two vectors | HirofumiTsuda | NORMAL | 2024-02-11T08:38:36.212077+00:00 | 2024-02-11T08:38:36.212105+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTake components in the following way:\n- take components included either of two vectors first\n- then take ones appearing in the two vectors\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe problem can be interp... | 0 | 0 | ['C++'] | 0 |
maximum-size-of-a-set-after-removals | 100% Solution using Set Data Structure | 100-solution-using-set-data-structure-by-imuu | \n# Complexity\n- Time complexity:\nO(n+m)\n\n- Space complexity:\nO(n+m)\n\n# Code\n\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) | Sourav4676 | NORMAL | 2024-02-10T17:01:08.011307+00:00 | 2024-02-10T17:01:08.011331+00:00 | 12 | false | \n# Complexity\n- Time complexity:\nO(n+m)\n\n- Space complexity:\nO(n+m)\n\n# Code\n```\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n Set<Integer> set1 = new HashSet<>();\n Set<Integer> set2 = new HashSet<>();\n Set<Integer> set3 = new HashSet<>();\n int ans... | 0 | 0 | ['Java'] | 0 |
maximum-size-of-a-set-after-removals | Easy Java Solution || Simple Freq Check || Beats 100% ✅✅ | easy-java-solution-simple-freq-check-bea-5l07 | 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 | vritant-goyal | NORMAL | 2024-02-07T06:07:10.295508+00:00 | 2024-02-07T06:08:15.440033+00:00 | 16 | false | # 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```\nclass Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n HashSet<Integer>st=new HashSet<>();\n ... | 0 | 0 | ['Array', 'Greedy', 'Java'] | 0 |
maximum-size-of-a-set-after-removals | Simplest Code|Greedy|C++ | simplest-codegreedyc-by-himanshu_0408-4ibt | 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 | himanshu_0408 | NORMAL | 2024-02-07T03:17:40.810341+00:00 | 2024-02-07T03:17:40.810374+00:00 | 9 | 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. $$... | 0 | 0 | ['Greedy', 'C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | [C++, Java, Python3] Palindromic Substrings + Non-overlapping Intervals | c-java-python3-palindromic-substrings-no-r0a6 | \nExplanation\nThis question is a combination of Palindromic Substring and Non-overlapping intervals\nhttps://leetcode.com/problems/palindromic-substrings/\nhtt | tojuna | NORMAL | 2022-11-13T04:00:54.217031+00:00 | 2022-11-13T06:43:26.238568+00:00 | 7,600 | false | \n**Explanation**\nThis question is a combination of Palindromic Substring and Non-overlapping intervals\nhttps://leetcode.com/problems/palindromic-substrings/\nhttps://leetcode.com/problems/non-overlapping-intervals/\n* First find all palindromic substrings with length >= k in O(n*k) and store their start and end in a... | 115 | 2 | ['C++', 'Java', 'Python3'] | 17 |
maximum-number-of-non-overlapping-palindrome-substrings | DP + Greedy | dp-greedy-by-votrubac-tywh | We precompute a 2d array pal that tells us whether a string between i and j is a palindrome (pal[i][j] == true).\n\nThis is the same DP approach as for 647. Pal | votrubac | NORMAL | 2022-11-13T04:03:42.478390+00:00 | 2022-11-15T09:11:47.691363+00:00 | 4,754 | false | We precompute a 2d array `pal` that tells us whether a string between `i` and `j` is a palindrome (`pal[i][j] == true`).\n\nThis is the same DP approach as for [647. Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/).\n\nThen, we use DP to find maximum number of splits.\n\n**Important Optimi... | 60 | 1 | ['C'] | 9 |
maximum-number-of-non-overlapping-palindrome-substrings | Simplest Solution | NO DP + ( why only k+1 ) | simplest-solution-no-dp-why-only-k1-by-h-rtkn | Too much Simple\n\n Main catch here was to avoid picking a palindromic substring with size greater than k+1 because if there exist a palindromic substring with | HarshitMaurya | NORMAL | 2022-11-13T14:14:54.690786+00:00 | 2022-11-14T11:14:58.881883+00:00 | 1,861 | false | # Too much Simple\n\n* Main catch here was to avoid picking a palindromic substring with size greater than k+1 because if there exist a palindromic substring with size greater than k+1 then it would definitely contain a palindromic substring with size at least k ( It was just basic observation ) And we are trying to mi... | 37 | 0 | ['Greedy', 'C', 'Java'] | 8 |
maximum-number-of-non-overlapping-palindrome-substrings | ✅ [Python/C++] recursive & iterative DP solutions (explained) | pythonc-recursive-iterative-dp-solutions-00eg | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs a Dynamic Programming* approach to explore all possible non-overlapping palindromes. | stanislav-iablokov | NORMAL | 2022-11-13T05:23:09.622814+00:00 | 2022-11-15T08:31:33.399812+00:00 | 1,316 | false | **\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs a *Dynamic Programming* approach to explore all possible non-overlapping palindromes. Time complexity is linear: **O(nk)**. Space complexity is linear: **O(n)**.\n\n**Comment.** If one palindrome is a substring of another palidrome then c... | 30 | 2 | [] | 5 |
maximum-number-of-non-overlapping-palindrome-substrings | [Python3] DP with Explanations | Only Check Substrings of Length k and k + 1 | python3-dp-with-explanations-only-check-y3wgr | Observation\nGiven the constraints, a solution with quadratic time complexity suffices for this problem. The key to this problem is to note that, if a given pal | xil899 | NORMAL | 2022-11-13T04:01:59.527569+00:00 | 2022-11-13T04:30:17.179494+00:00 | 1,809 | false | **Observation**\nGiven the constraints, a solution with quadratic time complexity suffices for this problem. The key to this problem is to note that, if a given palindromic substring has length greater or equal to `k + 2`, then we can always remove the first and last character of the substring without losing the optima... | 19 | 5 | ['Dynamic Programming', 'Python3'] | 6 |
maximum-number-of-non-overlapping-palindrome-substrings | [Java/C++] Simple DP | javac-simple-dp-by-virendra115-9ci8 | Only check substrings of length k and k + 1\n\nJava\njava\nclass Solution {\n public int maxPalindromes(String s, int k) {\n int ans = 0, n = s.length | virendra115 | NORMAL | 2022-11-13T04:00:43.417030+00:00 | 2022-11-13T04:16:10.339516+00:00 | 1,568 | false | Only check substrings of length k and k + 1\n\n**Java**\n```java\nclass Solution {\n public int maxPalindromes(String s, int k) {\n int ans = 0, n = s.length();\n int[] dp = new int[n + 1];\n for (int i = k - 1; i < n; i++) {\n dp[i + 1] = dp[i];\n if (helper(s, i-k+1, i)) ... | 17 | 4 | [] | 5 |
maximum-number-of-non-overlapping-palindrome-substrings | DP + Max Meetings in a Room | C + + | dp-max-meetings-in-a-room-c-by-megamind-dcdg | \n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n The problem can be broken into | megamind_ | NORMAL | 2022-11-13T04:01:37.661094+00:00 | 2022-11-13T04:11:41.223426+00:00 | 1,215 | false | \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n The problem can be broken into two parts:-\n\n - Finding all the start and end indices of palindromes in the string such that length of palindrome is k . *(This can be done in ... | 14 | 2 | ['C++'] | 2 |
maximum-number-of-non-overlapping-palindrome-substrings | [Python] DP Solution | python-dp-solution-by-lee215-u56q | Explanation\ndp[i] means the result for prefix string to s[i].\ndp[i] = dp[i-1], means s[i] is not used in palindrome substrings.\nThen we check substring with | lee215 | NORMAL | 2022-11-13T04:57:48.210728+00:00 | 2022-11-13T04:57:48.210764+00:00 | 951 | false | # **Explanation**\n`dp[i]` means the result for prefix string to `s[i]`.\n`dp[i] = dp[i-1]`, means `s[i]` is not used in palindrome substrings.\nThen we check substring with the `k` last characters,\nwith `s[i-k+1], s[i-k+2] ... s[i]`,\nif it\'s palindrome we have `dp[i] = dp[i - k] + 1`\n\nIf the above string is not p... | 11 | 0 | [] | 2 |
maximum-number-of-non-overlapping-palindrome-substrings | C++ - Both DP + Greedy Solution Explained - Clean Code | c-both-dp-greedy-solution-explained-clea-wn2n | Intuition\nThis question is going to mess with TLE if you don\'t memoize it properly.\nIt\'s very similar to Palindrome Paritioning, but requires condition of m | geekykant | NORMAL | 2022-11-13T05:12:09.493935+00:00 | 2022-11-13T06:20:56.239749+00:00 | 836 | false | **Intuition**\nThis question is going to mess with TLE if you don\'t memoize it properly.\nIt\'s very similar to [Palindrome Paritioning](https://leetcode.com/problems/palindrome-partitioning/), but requires condition of minLength `K`.\n\n**Method 1: DP Solution**\n```cpp\nint minLen;\nvector<vector<bool>> dp;\nunorder... | 8 | 0 | ['Dynamic Programming', 'C'] | 2 |
maximum-number-of-non-overlapping-palindrome-substrings | Java Greedy Approach | java-greedy-approach-by-zadeluca-c0g5 | \nclass Solution {\n public int maxPalindromes(String s, int k) {\n int count = 0;\n int idx = 0;\n \n // greedily check for pali | zadeluca | NORMAL | 2022-11-13T04:00:49.222842+00:00 | 2022-11-13T04:00:49.222893+00:00 | 800 | false | ```\nclass Solution {\n public int maxPalindromes(String s, int k) {\n int count = 0;\n int idx = 0;\n \n // greedily check for palindromes of length k or k + 1\n while (idx <= s.length() - k) {\n if (isPalindrome(s, idx, idx + k - 1)) {\n count++;\n ... | 8 | 0 | ['Greedy', 'Java'] | 3 |
maximum-number-of-non-overlapping-palindrome-substrings | [C++ ] Without using dp and palindrome function. | c-without-using-dp-and-palindrome-functi-5pn0 | \nclass Solution {\npublic:\n int maxPalindromes(string s, int k) {\n int n = s.size();\n int count = 0;\n for(int i=0;i<n;i++){\n | iamronnie847 | NORMAL | 2022-11-13T07:44:17.927694+00:00 | 2022-11-13T18:38:00.068375+00:00 | 281 | false | ```\nclass Solution {\npublic:\n int maxPalindromes(string s, int k) {\n int n = s.size();\n int count = 0;\n for(int i=0;i<n;i++){\n string str = "",str1="";\n for(int j=i;j<n;j++){\n str += s[j];\n str1 = s[j] + str1;\n if(str.... | 7 | 0 | ['String', 'C'] | 2 |
maximum-number-of-non-overlapping-palindrome-substrings | c++ solution using memoization | c-solution-using-memoization-by-dilipsut-teto | \nclass Solution {\npublic:\n int k;\n int n;\n int p[2001][2001];\n int memo[3000];\n int f(int idx)\n {\n if(idx>=n)\n {\n | dilipsuthar17 | NORMAL | 2022-11-13T06:24:01.871934+00:00 | 2022-12-01T04:44:58.164806+00:00 | 1,355 | false | ```\nclass Solution {\npublic:\n int k;\n int n;\n int p[2001][2001];\n int memo[3000];\n int f(int idx)\n {\n if(idx>=n)\n {\n return 0;\n }\n if(memo[idx]!=-1)\n {\n return memo[idx];\n }\n int ans=0;\n for(int i=idx;i<n;i... | 7 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | Java | 1 dimension DP | Explained | java-1-dimension-dp-explained-by-nadaral-3y8o | Intuition\ndp[i] means the amount of palindomres found up to index i (exclusive).\n\nWe will iterate over the string s and at every iteration the i index will r | nadaralp | NORMAL | 2022-11-13T16:02:08.678026+00:00 | 2022-11-13T16:06:47.985217+00:00 | 687 | false | # Intuition\n`dp[i]` means the amount of palindomres found up to index `i` (exclusive).\n\nWe will iterate over the string `s` and at every iteration the `i` index will represent the center of a palindrome.\n\nWe will try expanding from that center to the left and right, and if we are holding equality `A[left] == A[rig... | 6 | 0 | ['Java'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Simple Longest Palindromic Substring | Brute Force | C++ | simple-longest-palindromic-substring-bru-qqk8 | \n Describe your first thoughts on how to solve this problem. \nJust find longest palindromic substring greedly in every substring>=K\n\n# Code\n\nclass Solutio | rajat7k | NORMAL | 2022-11-13T04:22:55.915280+00:00 | 2022-11-13T04:22:55.915340+00:00 | 1,069 | false | \n<!-- Describe your first thoughts on how to solve this problem. -->\nJust find longest palindromic substring greedly in every substring>=K\n\n# Code\n```\nclass Solution {\npublic:\n \n int longestPalSubstr(string str)\n{\n int n = str.size();\n if (n < 2)\n return n;\n int maxLength = 1, start ... | 6 | 0 | ['Dynamic Programming', 'Greedy', 'C++'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | Java O(N) Solution | DP + Manacher's algorithm | java-on-solution-dp-manachers-algorithm-cf7gg | I implemented two different solution during the contest and even the brute force approach can pass all the test cases.\nThus, I guess this problem shouldn\'t be | hdchen | NORMAL | 2022-11-13T04:10:47.619315+00:00 | 2022-11-14T08:02:41.135641+00:00 | 595 | false | I implemented two different solution during the contest and even the brute force approach can pass all the test cases.\nThus, I guess this problem shouldn\'t be labeled as hard.\n\n#### Algorithm\n* dp[i] means the maximum number of non-overlapping palindrome substrings from cs[i...n-1]\n* Use brute-force or manacher\'... | 6 | 0 | ['Dynamic Programming', 'Java'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Simple C++ solution: No DP | simple-c-solution-no-dp-by-jenish_09-nos4 | \n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nHere we observe that if any stri | jenish_09 | NORMAL | 2022-11-18T16:17:40.946179+00:00 | 2022-11-18T16:17:40.946225+00:00 | 138 | false | \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere we observe that if any string which size is k+2 and string is palindrome then substring of that string whose size k is also palidrome so we check for substring whose size is... | 5 | 0 | ['C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | C++ || DP + Binary Search | c-dp-binary-search-by-puneet801-jgsf | \nclass Solution {\npublic:\n bool isPal(string &s,int i, int j){\n while(i < j){\n if(s[i++] != s[j--]){\n return false;\n | puneet801 | NORMAL | 2022-11-13T04:00:50.409431+00:00 | 2022-11-13T04:04:05.243170+00:00 | 483 | false | ```\nclass Solution {\npublic:\n bool isPal(string &s,int i, int j){\n while(i < j){\n if(s[i++] != s[j--]){\n return false;\n }\n }\n return true;\n }\n\t// Simple pick/notpick dp function\n int solve(int i, vector<pair<int,int>>&arr,vector<int>&dp){\n... | 5 | 0 | ['C', 'Binary Tree'] | 3 |
maximum-number-of-non-overlapping-palindrome-substrings | Python3 | Memoization | python3-memoization-by-dr_negative-p435 | \nclass Solution:\n def maxPalindromes(self, s: str, k: int) -> int:\n n=len(s)\n def checkIfPalindrome(i,j):\n while i<j:\n | dr_negative | NORMAL | 2022-11-20T10:40:02.568575+00:00 | 2022-11-20T10:40:02.568616+00:00 | 358 | false | ```\nclass Solution:\n def maxPalindromes(self, s: str, k: int) -> int:\n n=len(s)\n def checkIfPalindrome(i,j):\n while i<j:\n if s[i]!=s[j]:\n return False\n i+=1\n j-=1\n return True\n @lru_cache(2000)\n ... | 4 | 0 | ['Dynamic Programming', 'Memoization', 'Python3'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | Simplest Greedy Python Solution | O(1) Space | O(n*k) Time | simplest-greedy-python-solution-o1-space-p2nk | Intuition\nIf there is a substring of size k + 2 which is a palindrome, then for sure there is a substring of size k which is a palindrome. Similarly, if there | deepaklaksman | NORMAL | 2022-11-14T16:31:12.378417+00:00 | 2022-11-14T16:31:12.378457+00:00 | 343 | false | # Intuition\nIf there is a substring of size k + 2 which is a palindrome, then for sure there is a substring of size k which is a palindrome. Similarly, if there is a substring of size k + 3 which is a palindrome, then there is a substring of size k + 1 which is a palindrome.\n\n# Approach\nSo we can **greedily** start... | 4 | 0 | ['Greedy', 'Python', 'Python3'] | 3 |
maximum-number-of-non-overlapping-palindrome-substrings | ✅ C++ || recursion || memoization || dynamic programming | c-recursion-memoization-dynamic-programm-2u3o | Approach:- Checking each possibility through recursion,and doing memoization after that.\n\n\u2705 C++ || recursion || memoization || dynamic programming\nclas | niraj_1 | NORMAL | 2022-11-13T14:41:58.161339+00:00 | 2022-11-13T14:41:58.161363+00:00 | 270 | false | **Approach:- Checking each possibility through recursion,and doing memoization after that.**\n```\n\u2705 C++ || recursion || memoization || dynamic programming\nclass Solution {\npublic:\n int dp[2001][2001];\n bool isPal(string &s,int i,int j){\n while(i<j){\n if(s[i++]!=s[j--])return false;\... | 4 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | C++ || Dynamic Programming || Memoization || Explained with comments | c-dynamic-programming-memoization-explai-0krw | \nclass Solution {\n vector<vector<bool>> is; // this 2-D vector is used to check whether substring from i to j is palindrome or not.\n int n;\n vector | sarthu858 | NORMAL | 2022-11-13T06:00:03.704488+00:00 | 2022-11-13T08:25:11.409625+00:00 | 739 | false | ```\nclass Solution {\n vector<vector<bool>> is; // this 2-D vector is used to check whether substring from i to j is palindrome or not.\n int n;\n vector<int> dp;\n int solve(string& s, int i, int k) {\n // if we are at end of string we have 0 ans\n if(i >= n) return 0;\n \n // ... | 4 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | Easy DP solution using Java | easy-dp-solution-using-java-by-devkd-d2nj | Intuition\n Describe your first thoughts on how to solve this problem. \nAs it is a maximum/minimum type of problem with n number of solutions possible its tell | DevKD | NORMAL | 2022-11-13T04:06:02.612540+00:00 | 2022-11-13T04:06:02.612570+00:00 | 371 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs it is a maximum/minimum type of problem with n number of solutions possible its tell us we need to use recursion and to optimize it we use dp.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe need to check fro... | 4 | 0 | ['Dynamic Programming', 'Java'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | Beautiful Code: Optimizing Palindrome Substring Count with Memoization | beautiful-code-optimizing-palindrome-sub-d92n | \n# Intuition\nNote: here curr substring means (start - end),i wrote code so that it can be understood by everyone just by reading it\n\nThere are three action | whoisslimshady | NORMAL | 2023-06-27T13:06:07.704532+00:00 | 2023-06-27T13:06:07.704565+00:00 | 79 | false | \n# Intuition\nNote: here curr substring means (start - end),i wrote code so that it can be understood by everyone just by reading it\n\nThere are three action we can take at any possible moment \n1. curr substring as ans and increase the count make curr substring empty \n2. add char in curr substring and recurive on t... | 3 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Easiest(2d-DP and 1d-DP) | easiest2d-dp-and-1d-dp-by-piyush9818-v7gp | ```\n\t//2d dp if number is pal or not \n\tint ispal[2001][2001]={0};\n\t//1d dp for for optimizing recursion\n int dp[2001];\n int n;//length of string\n | piyush9818 | NORMAL | 2022-11-16T10:40:40.385950+00:00 | 2022-11-16T10:40:40.385989+00:00 | 524 | false | ```\n\t//2d dp if number is pal or not \n\tint ispal[2001][2001]={0};\n\t//1d dp for for optimizing recursion\n int dp[2001];\n int n;//length of string\n int fun(int index,int k)\n {\n if(index>=n)\n return 0;\n if(dp[index]!=-1)\n return dp[index];\n int ans=0;\n... | 3 | 0 | ['Dynamic Programming', 'Recursion'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | ✅ [Python] Very simple solution - O(n) || no DP | python-very-simple-solution-on-no-dp-by-5cw4c | Intuition\nSimilar to 647 https://leetcode.com/problems/palindromic-substrings/\nJust need to add the constraint - non-overlapping\n\n## Approach\nExpand from c | Meerka_ | NORMAL | 2022-11-13T18:12:47.877015+00:00 | 2022-11-13T18:13:17.290868+00:00 | 188 | false | ## Intuition\nSimilar to 647 https://leetcode.com/problems/palindromic-substrings/\nJust need to add the constraint - non-overlapping\n\n## Approach\nExpand from centers to make the time complexity O(N), space complexity O(1)\nOnly count the palindrome with shortest length (>=k)\nKeep track of the last end position to ... | 3 | 0 | ['Python3'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Dp solution. O(n^2) approach. | dp-solution-on2-approach-by-goyaltushar0-rm7c | Intuition\n Describe your first thoughts on how to solve this problem. \nFirst approach which hit our mind is to find all palindrome substrings starting from an | goyaltushar09 | NORMAL | 2022-11-13T05:54:10.845051+00:00 | 2022-11-13T06:03:41.775792+00:00 | 126 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst approach which hit our mind is to find all palindrome substrings starting from an index.\n\nThen calculate maximum no. of partition, we can get considering each possible substrings for an index.\n\neg: `[abababcdc]` , `k = 3`\npossi... | 3 | 0 | ['Dynamic Programming', 'C++'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | C++ | DP | Recursion | memoization | Easy to Understand | O(n*n) | c-dp-recursion-memoization-easy-to-under-oqcj | Approach\n\nLet us first get all the palindromic substring, to do this:\n\n1. Lets say we are checking palindromic substrings of length n, for index i to j, the | DevChoganwala | NORMAL | 2022-11-13T04:16:37.621698+00:00 | 2022-11-13T04:16:37.621737+00:00 | 396 | false | ## Approach\n<hr>\nLet us first get all the palindromic substring, to do this:\n\n1. Lets say we are checking palindromic substrings of length `n`, for index `i` to `j`, then, if `s[i] == s[j]` && `isPalindrome[i+1][j-1]`, we can set `isPalindrome[i][j] = 1`\n\nWe are essentially checking palindromes of length `n-2`, w... | 3 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C'] | 2 |
maximum-number-of-non-overlapping-palindrome-substrings | DP Solution | dp-solution-by-roboto7o32oo3-tkj6 | Code\n\nclass Solution {\npublic:\n \n vector<vector<bool>> isPalindrome(string& s){\n int n = s.size();\n vector<vector<bool>> dp(n, vector | roboto7o32oo3 | NORMAL | 2022-11-13T04:01:33.282206+00:00 | 2022-11-13T04:12:59.457639+00:00 | 1,645 | false | # Code\n```\nclass Solution {\npublic:\n \n vector<vector<bool>> isPalindrome(string& s){\n int n = s.size();\n vector<vector<bool>> dp(n, vector<bool>(n, false));\n \n for(int i=0; i<n; i++){\n dp[i][i] = true;\n }\n \n for(int i=0; i<n-1; i++){\n ... | 3 | 0 | ['Dynamic Programming', 'C++'] | 2 |
maximum-number-of-non-overlapping-palindrome-substrings | Easy Java Solution | easy-java-solution-by-sumitk7970-d9sr | \nclass Solution {\n int start = 0;\n int count = 0;\n \n public int maxPalindromes(String s, int k) {\n for(int i=0; i<s.length(); i++) {\n | Sumitk7970 | NORMAL | 2022-11-13T04:01:16.314452+00:00 | 2022-11-13T04:01:16.314512+00:00 | 1,011 | false | ```\nclass Solution {\n int start = 0;\n int count = 0;\n \n public int maxPalindromes(String s, int k) {\n for(int i=0; i<s.length(); i++) {\n helper(s, i, i, k);\n helper(s, i, i+1, k);\n }\n \n return count;\n }\n \n void helper(String s, int i, ... | 3 | 0 | ['Java'] | 1 |
maximum-number-of-non-overlapping-palindrome-substrings | Solution using dp | solution-using-dp-by-rohit_1610-mmig | \n\n<!-- # Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n- Space complexity:\nAdd your space complexity here, e.g. O(n) \n\n# Code | rohit_1610 | NORMAL | 2024-07-07T12:02:19.327819+00:00 | 2024-07-07T12:02:19.327880+00:00 | 51 | false | \n\n<!-- # Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ \n- Space complexity:\nAdd your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool check(int i, int j, string &s, vector<vector<int>> &palindrome) {\n if (palindrome[i][j] != -1)... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Java/C++ Clean Easy Solution || With Detail Description | javac-clean-easy-solution-with-detail-de-4qxe | Complexity\n- Time complexity:O(n*k)\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# Co | Shree_Govind_Jee | NORMAL | 2024-07-02T15:28:16.460271+00:00 | 2024-07-02T15:28:16.460297+00:00 | 112 | false | # Complexity\n- Time complexity:$$O(n*k)$$\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```\nclass Solution {\n\n private boolean isPalindrom(String str, int start, int end) {\n while (start < end) {\n ... | 2 | 0 | ['String', 'Dynamic Programming', 'Greedy', 'Recursion', 'Memoization', 'Java'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Be Greedy | be-greedy-by-cs22m020-ywf7 | Intuition\n Describe your first thoughts on how to solve this problem. \nStart at i:\nif : i to i+k-1 is a pallindrome i=i+k\nelse if : i to i+k is a pallindrom | cs22m020 | NORMAL | 2023-10-08T10:35:36.943504+00:00 | 2023-10-08T10:35:36.943522+00:00 | 101 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nStart at i:\nif : i to i+k-1 is a pallindrome i=i+k\nelse if : i to i+k is a pallindrome i=i+k+1;\nelse : i=i+1\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Complexity\n- Time complexity:\n<!-- Add your ti... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | C++ | Sliding Window Approach | Easy to Understand | c-sliding-window-approach-easy-to-unders-q7n6 | \n# Code\n\nclass Solution {\n bool isPalindrome(string s, int i, int j){\n while(i<j){\n if(s[i++]!=s[j--]){\n return false | PulkitAgga01 | NORMAL | 2023-03-19T17:03:53.952990+00:00 | 2023-03-19T17:03:53.953040+00:00 | 353 | false | \n# Code\n```\nclass Solution {\n bool isPalindrome(string s, int i, int j){\n while(i<j){\n if(s[i++]!=s[j--]){\n return false;\n }\n }\n return true;\n }\npublic:\n int maxPalindromes(string s, int k) {\n int ans = 0;\n for(int i=0; i<s.... | 2 | 0 | ['Sliding Window', 'C++'] | 3 |
maximum-number-of-non-overlapping-palindrome-substrings | Easy to understand solution in java using center expansion technique in O(n) | easy-to-understand-solution-in-java-usin-x9ua | \n# Approach\nUsing each element of the array as center keep on building the pallindrome as soon as it reaches the min length criteria just stop the operation a | sarja830 | NORMAL | 2023-02-09T23:12:56.966540+00:00 | 2024-01-23T12:23:43.822892+00:00 | 410 | false | \n# Approach\nUsing each element of the array as center keep on building the pallindrome as soon as it reaches the min length criteria just stop the operation and return index next to it because it is already used in the pallindrome once and we dont want overlapping pallindromes. \nMaintain a used array to track whethe... | 2 | 0 | ['Java'] | 2 |
maximum-number-of-non-overlapping-palindrome-substrings | ✅ [C++] || DP + Greedy || Most intuitive solution || easy to understand | c-dp-greedy-most-intuitive-solution-easy-w0vz | You can check for each index j what all are the index i for which i-j is a palindrome and store it in a map (O(n^2)). Now using top down, check for each index i | iamvaibhav070101 | NORMAL | 2022-11-16T20:05:07.984771+00:00 | 2022-11-16T20:05:34.226283+00:00 | 186 | false | You can check for each index ```j``` what all are the index ```i``` for which ```i-j``` is a palindrome and store it in a map ```(O(n^2))```. Now using top down, check for each index ```i``` what can be a possible selection of ```j``` using the map, and call again recursively on ```j-1``` (Note that if ```j-1<0``` then... | 2 | 0 | ['Dynamic Programming', 'Greedy', 'C'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Detailed Explanation ✅ - Dynamic Programming Solution O(N*N) | detailed-explanation-dynamic-programming-yce4 | Intuition\nI found out the find maximum number of valid substrings in every interval \n[i,n-1], where i vary from (0 to n-1)\nand dp[0] is the answer\n\n# Appro | bhavya_kawatra13 | NORMAL | 2022-11-14T12:08:29.507913+00:00 | 2022-11-14T15:14:45.594673+00:00 | 479 | false | # Intuition\nI found out the find maximum number of valid substrings in every interval \n[i,n-1], where i vary from (0 to n-1)\nand dp[0] is the answer\n\n# Approach\nWe iterated over the string and for each character \'i\', we stored the result of \'maximum number of valid substrings it can make in range i to n-1\' in... | 2 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | O(n) solution with Manacher's algorithm + checking the shortest palindrome of any given center | on-solution-with-manachers-algorithm-che-1p2t | Intuition\nManacher\'s algorithm computes the longest palindrome of all possible centers in linear time. Combined with the fact that the shortest palindrome tha | chuan-chih | NORMAL | 2022-11-13T07:45:09.499880+00:00 | 2022-11-13T07:45:09.499945+00:00 | 254 | false | # Intuition\n[Manacher\'s algorithm](https://en.wikipedia.org/wiki/Longest_palindromic_substring#Manacher\'s_algorithm) computes the longest palindrome of all possible centers in linear time. Combined with the fact that the shortest palindrome that starts later and ends earlier is always preferred since the answer up t... | 2 | 0 | ['Python3'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | [JavaScript] Simple and fast brute force 😀 | javascript-simple-and-fast-brute-force-b-9eh8 | If there is a palindrome string of length N where N > k + 1, the string can be always "trimmed" to a substring of length k or k + 1. E.g. for k = 3, abcddcba => | m12s44 | NORMAL | 2022-11-13T05:54:14.527606+00:00 | 2022-11-13T05:54:14.527649+00:00 | 94 | false | 1. If there is a palindrome string of length N where N > k + 1, the string can be always "trimmed" to a substring of length k or k + 1. E.g. for k = 3, ab**cddc**ba =>cddc; or abc**ded**cba => ded\n2. As far as we need to find a maximum number of substrings in an optimal selection we can ignore all palindromes longer t... | 2 | 0 | ['JavaScript'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | [Python3] greedy - only check length k and k + 1 | python3-greedy-only-check-length-k-and-k-b57v | \nclass Solution:\n def maxPalindromes(self, s: str, k: int) -> int:\n ans = 0\n l = 0\n while l<len(s):\n cdd1 = s[l:l+k]\n | nxiayu | NORMAL | 2022-11-13T05:03:53.424661+00:00 | 2022-11-13T05:05:35.296517+00:00 | 336 | false | ```\nclass Solution:\n def maxPalindromes(self, s: str, k: int) -> int:\n ans = 0\n l = 0\n while l<len(s):\n cdd1 = s[l:l+k]\n if len(cdd1)>=k and cdd1 == cdd1[::-1]:\n ans += 1\n l = l+k\n continue\n cdd2 = s[l:l+k+1... | 2 | 0 | ['Greedy', 'Python', 'Python3'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Longest Palindromic Substring || Easy to Understand || Java || Expanding around a fixed pivot | longest-palindromic-substring-easy-to-un-b2qd | The intution of the problem can be very well driven from the idea of the Longest Palindromic Substring problem.\n\nLets first review the code for the longest pa | Utkarsh_09 | NORMAL | 2022-11-13T04:19:31.159805+00:00 | 2022-11-13T04:27:17.480490+00:00 | 375 | false | The **intution of the problem can be very well driven from the idea** of the [Longest Palindromic Substring](http://leetcode.com/problems/longest-palindromic-substring/) problem.\n\nLets first review the code for the longest palindromic substring:\n```\nclass Solution {\n public int expand(int left, int right, Strin... | 2 | 1 | ['Java'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Java Solution | java-solution-by-solved-8fz1 | \nclass Solution {\n public int maxPalindromes(String s, int k) {\n int result = 0;\n for (int i = 0; i < s.length(); i++) {\n if (i | solved | NORMAL | 2022-11-13T04:01:27.187588+00:00 | 2022-11-13T04:01:27.187629+00:00 | 336 | false | ```\nclass Solution {\n public int maxPalindromes(String s, int k) {\n int result = 0;\n for (int i = 0; i < s.length(); i++) {\n if (isPalindrome(s, i, i + k - 1)) {\n result++;\n i = i + k - 1;\n } else if (isPalindrome(s, i, i + k)) {\n ... | 2 | 0 | ['Java'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Palindrome Matrix pre-computation + 1D memoization DP | palindrome-matrix-pre-computation-1d-mem-ojju | Code | vats_lc | NORMAL | 2024-12-27T08:02:50.098058+00:00 | 2024-12-27T08:02:50.098058+00:00 | 46 | false | # Code
```cpp []
class Solution {
public:
int getAns(int i, int n, vector<vector<int>>& palin, int& k,
vector<int>& dp) {
if (i == n)
return 0;
if (dp[i] != -1)
return dp[i];
int nt = getAns(i + 1, n, palin, k, dp), ans = 0;
for (int j = i + k -... | 1 | 0 | ['C++'] | 0 |
maximum-number-of-non-overlapping-palindrome-substrings | Crystal clear javascript code, not using GPT ! | crystal-clear-javascript-code-not-using-tnc5f | Made a repo with all my DSA solutions, you should check it out \nhttps://github.com/Abhaydutt2003/DataStructureAndAlgoPractice/tree/master/src/Strings\n\n\n\n# | AbhayDutt | NORMAL | 2024-05-27T04:35:19.690465+00:00 | 2024-05-27T04:35:19.690509+00:00 | 13 | false | Made a repo with all my DSA solutions, you should check it out \nhttps://github.com/Abhaydutt2003/DataStructureAndAlgoPractice/tree/master/src/Strings\n\n\n\n# Code\n```\n/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar maxPalindromes = function (s, k){\n let dpPal = new Array(s.length+1)... | 1 | 0 | ['JavaScript'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.