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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
base-7 | ☑️ Converting number to it's Base 7 form. ☑️ | converting-number-to-its-base-7-form-by-5isg7 | Code | Abdusalom_16 | NORMAL | 2025-02-14T04:16:45.582478+00:00 | 2025-02-14T04:16:45.582478+00:00 | 128 | false | # Code
```dart []
class Solution {
String convertToBase7(int num) {
return num.toRadixString(7);
}
}
``` | 1 | 0 | ['Math', 'Dart'] | 0 |
base-7 | Easy solution | easy-solution-by-koushik_55_koushik-z8ky | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Koushik_55_Koushik | NORMAL | 2025-02-05T14:00:16.045814+00:00 | 2025-02-05T14:00:16.045814+00:00 | 241 | 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
`... | 1 | 0 | ['Python3'] | 0 |
base-7 | Beats 100% || Efficient Solution || Simple Logic | beats-100-efficient-solution-simple-logi-699n | ApproachObtaining every digit from the int(abs) and form a string ; Reverse it to obtain the result.Complexity
Time complexity:
Space complexity:
Code | AbhayForCodes | NORMAL | 2025-01-23T05:38:16.700067+00:00 | 2025-01-23T05:38:16.700067+00:00 | 250 | false | # Approach
Obtaining every digit from the int(abs) and form a string ; Reverse it to obtain the result.
# Complexity
- Time complexity:
- Space complexity:

<!-- Add your space com... | 1 | 0 | ['C++'] | 0 |
base-7 | W solution using c | w-solution-using-c-by-akash_mac-fzlo | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Akash_mac | NORMAL | 2025-01-08T04:37:44.082810+00:00 | 2025-01-08T04:37:44.082810+00:00 | 182 | 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
`... | 1 | 0 | ['C++'] | 0 |
base-7 | Beginner's logic ( 0 ms) | beginners-logic-0-ms-by-dinhvanphuc-r0x4 | IntuitionApproachJust convert num mod 7 to string and append it to the first place by using the '+', then check if negative then append '-'. Remember that u hav | DinhVanPhuc | NORMAL | 2024-12-31T04:10:41.480268+00:00 | 2024-12-31T04:10:41.480268+00:00 | 336 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
Just convert num mod 7 to string and append it to the first place by using the '+', then check if negative then append '-'. Remember that u have to make the num positive or... | 1 | 0 | ['C++'] | 0 |
base-7 | BRUTE FORCE APPROACH | brute-force-approach-by-varun_balakrishn-cc2c | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Varun_Balakrishnan | NORMAL | 2024-12-28T17:24:43.158399+00:00 | 2024-12-28T17:24:43.158399+00:00 | 455 | 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
`... | 1 | 0 | ['Java'] | 0 |
base-7 | ✅0ms python3 solution || beats 100% | 0ms-python3-solution-beats-100-by-rajesh-cd5l | Beats 100% 0ms in python3converting to base 7 is of the form1.check if the number is zero (base condition) then return 02.take a list, l to store the remainders | Rajesh_uda | NORMAL | 2024-12-24T19:08:15.859801+00:00 | 2024-12-24T19:08:15.859801+00:00 | 455 | false | # Beats 100% 0ms in python3
## converting to base 7 is of the form

1.check if the number is zero (base condition) then return 0
2.take a list, l to store the remainders after division
3.append the rema... | 1 | 0 | ['Python3'] | 0 |
base-7 | SINGLE LINE JAVA SOLUTION -TWO APPROACHES | single-line-java-solution-two-approaches-ulvr | APPROACH 1\n\nclass Solution {\n public String convertToBase7(int num) {\n return Integer.toString(num, 7); \n }\n}\n\nAPPROACH 2\n# Code\njava []\n | THANMAYI01 | NORMAL | 2024-11-09T10:33:44.760551+00:00 | 2024-11-09T10:33:44.760594+00:00 | 483 | false | APPROACH 1\n```\nclass Solution {\n public String convertToBase7(int num) {\n return Integer.toString(num, 7); \n }\n}\n```\nAPPROACH 2\n# Code\n```java []\nclass Solution {\n public String convertToBase7(int num) {\n if(num<0) return "-"+convertToBase7(-num);\n if(num<7) return Integer.toS... | 1 | 0 | ['Math', 'Java'] | 1 |
base-7 | Best solution for Base Conversion | best-solution-for-base-conversion-by-paw-v46o | Intuition\n Describe your first thoughts on how to solve this problem. \nTo convert an integer to base 7, I need to repeatedly divide the number by 7, collectin | pawan_leel | NORMAL | 2024-11-01T17:09:44.558994+00:00 | 2024-11-01T17:09:44.559021+00:00 | 80 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo convert an integer to base 7, I need to repeatedly divide the number by 7, collecting the remainders. These remainders represent the digits in the new base, starting from the least significant digit.\n\n# Approach\n<!-- Describe your a... | 1 | 0 | ['Java'] | 0 |
base-7 | Easy and Simple code to solve Base 7. | easy-and-simple-code-to-solve-base-7-by-bg7wl | Intuition\nTo convert a number to base 7, we continuously divide the number by 7 and store the remainder at each step. These remainders represent the digits in | vijay_s_11335 | NORMAL | 2024-09-05T14:02:46.044692+00:00 | 2024-09-05T14:02:46.044714+00:00 | 53 | false | # Intuition\nTo convert a number to base 7, we continuously divide the number by 7 and store the remainder at each step. These remainders represent the digits in base 7, starting from the least significant digit. If the number is negative, we simply append a minus sign at the end.\n\n# Approach\n1. Handle the base case... | 1 | 0 | ['C++'] | 0 |
base-7 | Cpp Solution | cpp-solution-by-dileep_gampala-3bkj | Code\n\nclass Solution {\npublic:\n string convertToBase7(int num) {\n string ans="";\n int i;\n if(num==0)\n {\n retu | Dileep_Gampala | NORMAL | 2024-07-29T20:25:31.979758+00:00 | 2024-07-29T20:25:31.979778+00:00 | 20 | false | # Code\n```\nclass Solution {\npublic:\n string convertToBase7(int num) {\n string ans="";\n int i;\n if(num==0)\n {\n return "0";\n }\n if (num < 0)\n {\n return "-" + convertToBase7(-num);\n }\n while(num!=0)\n {\n ... | 1 | 0 | ['C++'] | 0 |
base-7 | 100% beat - very simple solution in C++ | 100-beat-very-simple-solution-in-c-by-ja-vnw7 | 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 | jainam1512 | NORMAL | 2024-05-27T06:25:10.180417+00:00 | 2024-05-27T06:25:10.180444+00:00 | 347 | 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)$$ --... | 1 | 0 | ['C++'] | 0 |
base-7 | beats 99.31%|| easy python solution | beats-9931-easy-python-solution-by-md__j-1be2 | \nclass Solution:\n def convertToBase7(self, num: int) -> str:\n if num == 0:\n return "0"\n \n res = ""\n is_negative | MD__JAKIR1128__ | NORMAL | 2024-04-25T09:35:30.438403+00:00 | 2024-04-25T09:35:30.438437+00:00 | 1 | false | ```\nclass Solution:\n def convertToBase7(self, num: int) -> str:\n if num == 0:\n return "0"\n \n res = ""\n is_negative = num < 0\n num = abs(num)\n \n while num > 0:\n remainder = num % 7\n res = str(remainder) + res\n nu... | 1 | 0 | [] | 0 |
base-7 | ✅ 1 Line Solution Beats 100% with Java ✅ | 1-line-solution-beats-100-with-java-by-k-gx9q | 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 | kien-dev | NORMAL | 2024-04-14T09:45:11.409464+00:00 | 2024-04-14T09:45:11.409495+00:00 | 499 | 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)$$ --... | 1 | 0 | ['Java'] | 2 |
base-7 | the best solution | the-best-solution-by-a-fr0stbite-zwxq | Intuition\nP.S. the title is a serious exagration\n\nsplit it up, see what each digit is, add the negative sign when needed.\n\n# some stuff\nAlso, if you like | a-fr0stbite | NORMAL | 2024-03-05T06:01:38.187001+00:00 | 2024-03-05T06:01:38.187030+00:00 | 18 | false | # Intuition\nP.S. the title is a serious exagration\n\nsplit it up, see what each digit is, add the negative sign when needed.\n\n# some stuff\nAlso, if you like the 2nd code snippet or just appreciat the short explanation and 1st code, plz upvote!\n\n# Code\nmy real code\n```\nclass Solution:\n def convertToBase7(s... | 1 | 0 | ['Python3'] | 0 |
base-7 | Convert to Base | Time: O(log(N)) | Space: O(log(N)) | convert-to-base-time-ologn-space-ologn-b-22va | Complexity\n- Time complexity: $O(\log{N})$\n- Space complexity: $O(\log{N})$\n\n# Code 1: Number.toString\nUses the built-in base conversion feature of Number. | rojas | NORMAL | 2023-10-26T16:48:24.215389+00:00 | 2023-11-04T18:54:40.311153+00:00 | 38 | false | # Complexity\n- Time complexity: $O(\\log{N})$\n- Space complexity: $O(\\log{N})$\n\n# Code 1: Number.toString\nUses the built-in base conversion feature of [Number.toString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString). It can convert a number to a string in any bas... | 1 | 0 | ['TypeScript', 'JavaScript'] | 1 |
base-7 | Simple java Solution Beats 100% | simple-java-solution-beats-100-by-bhush9-dvmy | 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 | bhush9699 | NORMAL | 2023-10-17T07:02:04.882898+00:00 | 2023-10-17T07:02:04.882926+00:00 | 752 | 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)$$ --... | 1 | 0 | ['Java'] | 0 |
base-7 | Best Java Solution | best-java-solution-by-ravikumar50-n90s | 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 | ravikumar50 | NORMAL | 2023-09-19T20:51:53.999987+00:00 | 2023-09-19T20:51:54.000014+00:00 | 330 | 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)$$ --... | 1 | 0 | ['Java'] | 1 |
base-7 | 504. Base 7 💻 💻|| 🔥🔥 JAVA code... | 504-base-7-java-code-by-jayakumar__s-hziz | Code\n\nclass Solution {\n public String convertToBase7(int num) {\n String str = "";\n int a = 0;\n if(num == 0){\n return " | Jayakumar__S | NORMAL | 2023-06-25T14:45:16.438001+00:00 | 2023-06-25T14:45:27.265014+00:00 | 573 | false | # Code\n```\nclass Solution {\n public String convertToBase7(int num) {\n String str = "";\n int a = 0;\n if(num == 0){\n return "0"+str;\n }\n if(num<0){\n num = num * (-1);\n a++;\n }\n\n while(num>0){\n str= num%7+ str;\n... | 1 | 0 | ['Java'] | 1 |
base-7 | 1 Liner Java Code Beats 100% || Easy to Understand | 1-liner-java-code-beats-100-easy-to-unde-anqa | 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 | jashan_pal_singh_sethi | NORMAL | 2023-06-22T12:20:33.675286+00:00 | 2023-06-22T12:21:06.674730+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)$$ --... | 1 | 0 | ['String', 'Java'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ (Backtrack : C++ users, please pass string by reference to PASS) | c-backtrack-c-users-please-pass-string-b-uojg | My YouTube Channel - https://www.youtube.com/@codestorywithMIK\n\n/*\nSimple explanation :\nif you notice I am trying all three possibilities :-\n\n 1) I pic | mazhar_mik | NORMAL | 2021-09-12T04:25:36.422823+00:00 | 2023-04-15T03:47:14.659947+00:00 | 9,065 | false | My YouTube Channel - https://www.youtube.com/@codestorywithMIK\n```\n/*\nSimple explanation :\nif you notice I am trying all three possibilities :-\n\n 1) I pick s[i] for s1 but don\'t pick s[i] for s2 (because they should be disjoint)\n - I explore this path and find the result (and then backtrack)\n\n 2) ... | 209 | 6 | [] | 24 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Mask DP | mask-dp-by-votrubac-6q82 | We have 2^n possible palindromes, and each of them can be represented by a mask [1 ... 4096] (since n is limited to 12).\n\nFirst, we check if a mask represents | votrubac | NORMAL | 2021-09-12T04:00:48.115219+00:00 | 2021-09-12T21:49:48.836244+00:00 | 12,725 | false | We have `2^n` possible palindromes, and each of them can be represented by a mask `[1 ... 4096]` (since `n` is limited to `12`).\n\nFirst, we check if a mask represents a valid palindrome, and if so, store the length (or, number of `1` bits) in `dp`.\n\nThen, we check all non-zero masks `m1` against all non-intersectin... | 118 | 6 | ['C', 'Java'] | 23 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Java - Simple Recursion | java-simple-recursion-by-shreyash1-oh8i | \nclass Solution {\n \n int max = 0;\n public int maxProduct(String s) {\n \n char[] c = s.toCharArray();\n dfs(c, 0, "", "");\n | shreyash1 | NORMAL | 2021-09-12T04:03:01.702257+00:00 | 2021-09-12T13:45:14.249066+00:00 | 6,627 | false | ```\nclass Solution {\n \n int max = 0;\n public int maxProduct(String s) {\n \n char[] c = s.toCharArray();\n dfs(c, 0, "", "");\n \n return max;\n }\n \n public void dfs(char[] c, int i, String s1, String s2){\n \n if(i >= c.length){\n \n ... | 72 | 12 | ['Backtracking', 'Recursion', 'Java'] | 19 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [Python] Clean & Simple, bitmask | python-clean-simple-bitmask-by-yo1995-q42m | python\nclass Solution:\n def maxProduct(self, s: str) -> int:\n # n <= 12, which means the search space is small\n n = len(s)\n arr = [ | yo1995 | NORMAL | 2021-09-12T04:43:29.298317+00:00 | 2021-09-12T04:47:47.141843+00:00 | 4,032 | false | ```python\nclass Solution:\n def maxProduct(self, s: str) -> int:\n # n <= 12, which means the search space is small\n n = len(s)\n arr = []\n \n for mask in range(1, 1<<n):\n subseq = \'\'\n for i in range(n):\n # convert the bitmask to the act... | 39 | 0 | ['Python'] | 7 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ Backtracking Solution [EXPLAINED] [ACCEPTED} | c-backtracking-solution-explained-accept-z85j | APPROACH:\nBy seeing the constraints, it can be inferred that brute force approach should work fine.\nTo make disjoint subsequence we\'ll use 2 strings . Now, a | rishabh_devbanshi | NORMAL | 2021-09-13T06:21:02.225537+00:00 | 2021-09-13T06:22:30.247686+00:00 | 2,720 | false | **APPROACH:**\nBy seeing the constraints, it can be inferred that brute force approach should work fine.\nTo make disjoint subsequence we\'ll use 2 strings . Now, at everry character i in string we have 3 choices:\n1) include that char in first string\n2) include that char in second string\n3) exclude that char from bo... | 31 | 0 | ['Backtracking', 'C'] | 5 |
maximum-product-of-the-length-of-two-palindromic-subsequences | c++ solution (lcs) | c-solution-lcs-by-dilipsuthar60-vuhr | https://leetcode.com/problems/longest-palindromic-subsequence/\n\nclass Solution {\npublic:\n int lps(string &s)\n {\n int n=s.size();\n str | dilipsuthar17 | NORMAL | 2021-09-12T04:11:42.663594+00:00 | 2023-01-14T09:52:22.923919+00:00 | 3,237 | false | [https://leetcode.com/problems/longest-palindromic-subsequence/](http://)\n```\nclass Solution {\npublic:\n int lps(string &s)\n {\n int n=s.size();\n string s1=s;\n string s2=s;\n reverse(s2.begin(),s2.end());\n int dp[s.size()+1][s.size()+1];\n memset(dp,0,sizeof(dp));\... | 30 | 2 | ['C', 'Bitmask', 'C++'] | 4 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [Python] True O(2^n) dp on subsets solution, explained | python-true-o2n-dp-on-subsets-solution-e-r0xl | I saw several dp solution, which states that they have O(2^n) complexity, but they use bit manipulations, such as looking for first and last significant bit, wh | dbabichev | NORMAL | 2021-09-12T10:34:57.187179+00:00 | 2021-09-12T10:34:57.187212+00:00 | 2,930 | false | I saw several `dp` solution, which states that they have `O(2^n)` complexity, but they use bit manipulations, such as looking for first and last significant bit, which we can not say is truly `O(1)`. So I decided to write my own **true** `O(2^n)` solution.\n\nLet `dp(mask)` be the maximum length of palindrome if we all... | 28 | 0 | ['Dynamic Programming'] | 6 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python 3 || 5 lines, greedy || T/S: 95% / 42% | python-3-5-lines-greedy-ts-95-42-by-spau-by53 | Here\'s the plan:\n1. We generate all subsequences of s as lists of characters.\n\n2. We filter that list for palindromes.\n3. We compare each pair of palindrom | Spaulding_ | NORMAL | 2024-08-03T03:29:56.752651+00:00 | 2024-08-03T05:13:22.455894+00:00 | 532 | false | Here\'s the plan:\n1. We generate all subsequences of `s` as lists of characters.\n\n2. We filter that list for palindromes.\n3. We compare each pair of palindromes, first to see whether they are disjoint, and if so, determine the product of their lengths.\n4. We determine the maximum product and return it as the answe... | 14 | 0 | ['Python3'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python Bitmask | python-bitmask-by-colwind-a6fb | \ndef maxProduct(self, s: str) -> int:\n mem = {}\n n = len(s)\n for i in range(1,1<<n):\n tmp = ""\n for j in range( | colwind | NORMAL | 2021-09-12T04:09:33.371950+00:00 | 2021-09-12T04:09:33.371985+00:00 | 921 | false | ```\ndef maxProduct(self, s: str) -> int:\n mem = {}\n n = len(s)\n for i in range(1,1<<n):\n tmp = ""\n for j in range(n):\n if i>>j & 1 == 1:\n tmp += s[j]\n if tmp == tmp[::-1]:\n mem[i] = len(tmp)\n res = 0... | 13 | 3 | [] | 2 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Video solution | Intuition and Approach explained in detail | C++ | Backtracking | video-solution-intuition-and-approach-ex-381u | Video\nHello every one i have created a video solution for this problem and solved this video by developing intutition for backtracking (its in hindi), i am pre | _code_concepts_ | NORMAL | 2024-05-06T06:36:28.363331+00:00 | 2024-07-06T21:12:17.480871+00:00 | 589 | false | # Video\nHello every one i have created a video solution for this problem and solved this video by developing intutition for backtracking (its in hindi), i am pretty sure you will never have to look for solution for this video ever again after watching this.\n\n\nThis video is the part of my playlist "Master backtracki... | 12 | 0 | ['C++'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Easy Understand | Simple Method | Java | Python ✅ | easy-understand-simple-method-java-pytho-mde0 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nUse mask to save all co | czshippee | NORMAL | 2023-04-08T05:08:00.671870+00:00 | 2023-04-21T02:26:53.087128+00:00 | 2,251 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse mask to save all combination in hashmap and use "&" bit manipulation to check if two mask have repeated letter.\n\n# Complexity\n- Time complexity:\n<!-- Add your ... | 11 | 0 | ['Bit Manipulation', 'Bitmask', 'Python', 'Java', 'Python3'] | 2 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ Backtrack Solution | c-backtrack-solution-by-anubhvshrma18-ien5 | \nclass Solution {\npublic:\n int ans = 0;\n bool ispal(string &n){\n int i=0,j=n.length()-1;\n while(i<j){\n if(n[i]!=n[j]){\n | anubhvshrma18 | NORMAL | 2021-09-12T05:57:13.667924+00:00 | 2021-09-12T05:57:13.667967+00:00 | 618 | false | ```\nclass Solution {\npublic:\n int ans = 0;\n bool ispal(string &n){\n int i=0,j=n.length()-1;\n while(i<j){\n if(n[i]!=n[j]){\n return false;\n }\n i++,j--;\n }\n return true;\n }\n \n void temp(string &ori,int i,string a,strin... | 11 | 2 | ['Backtracking', 'C'] | 3 |
maximum-product-of-the-length-of-two-palindromic-subsequences | 15 Lines of Code Easy Brutal Force Java Solution O(3^12 *12) Backtrack Solution | 15-lines-of-code-easy-brutal-force-java-w9oic | As long as I see the constraint is 0<len<12, I try to use brutal force which is backtrack.\nSo each position char can be either:\n1) pick by s1\n2) pick by s2\n | davidluoyes | NORMAL | 2021-09-12T04:04:35.158082+00:00 | 2021-09-12T04:05:40.419993+00:00 | 840 | false | As long as I see the constraint is 0<len<12, I try to use brutal force which is backtrack.\nSo each position char can be either:\n1) pick by s1\n2) pick by s2\n3) pick by nobody.\n```\nclass Solution {\n int max = 0;\n public int maxProduct(String s) {\n backtrack(s,0,"","");\n return max;\n }\n ... | 11 | 3 | [] | 2 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [Java] Backtracking Solution | java-backtracking-solution-by-abhijeetma-3bod | \nclass Solution {\n public int maxProduct(String s) {\n return dfs(s.toCharArray(),"","",0,0);\n }\n \n public int dfs(char[] arr,String s,S | abhijeetmallick29 | NORMAL | 2021-09-12T05:06:42.758182+00:00 | 2021-09-12T05:54:09.321356+00:00 | 1,312 | false | ```\nclass Solution {\n public int maxProduct(String s) {\n return dfs(s.toCharArray(),"","",0,0);\n }\n \n public int dfs(char[] arr,String s,String p,int pos,int max){\n if(pos == arr.length){\n if(isValid(s) && isValid(p))max = Math.max(max,s.length() * p.length());\n ... | 10 | 0 | ['Java'] | 3 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Bit Masking | bit-masking-by-kira3018-uuft | \nclass Solution {\npublic:\n int maxProduct(string s) {\n int n = s.length();\n int p = pow(2,n);\n vector<pair<int,int> > vec;\n | kira3018 | NORMAL | 2021-09-12T04:10:54.057618+00:00 | 2021-09-12T04:10:54.057644+00:00 | 850 | false | ```\nclass Solution {\npublic:\n int maxProduct(string s) {\n int n = s.length();\n int p = pow(2,n);\n vector<pair<int,int> > vec;\n for(int i = 1;i < p;i++){\n int a = isPalindrome(s,i);\n if(a != -1)\n vec.push_back({i,a}); \n }\n int an... | 10 | 1 | [] | 2 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ || Backtracking Solution || Intuition Explained | c-backtracking-solution-intuition-explai-h6qq | Intuition:\n\nIdea is to form all combinations of subsequences that are palindromic, that are not overlapping i.e first string and second string should not have | i_quasar | NORMAL | 2021-09-12T10:52:16.522842+00:00 | 2021-09-12T10:52:37.060662+00:00 | 498 | false | **Intuition:**\n\nIdea is to form all combinations of subsequences that are palindromic, that are not overlapping i.e *first* string and *second* string should not have any common element from main string. Out of all possible *first* and *second* strings, we find product of `first.size() * second.size()` . In the end w... | 9 | 0 | ['Backtracking', 'Recursion'] | 3 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ DP from O(3^N) to O(2^N) | c-dp-from-o3n-to-o2n-by-lzl124631x-bek7 | See my latest update in repo LeetCode\n\n## Solution 1. Bitmask DP\n\nLet dp[mask] be the length of the longest palindromic subsequence within the subsequence r | lzl124631x | NORMAL | 2021-09-12T06:25:42.433990+00:00 | 2021-09-12T06:43:56.700016+00:00 | 1,261 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Bitmask DP\n\nLet `dp[mask]` be the length of the longest palindromic subsequence within the subsequence represented by `mask`.\n\nThe answer is `max( dp[m] * dp[(1 << N) - 1 - m] | 1 <= m < 1 << N )`. (`(1 << N) - 1 - m)`... | 9 | 1 | [] | 2 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [C++] Simple Solution using Backtracking | c-simple-solution-using-backtracking-by-t5fpj | \n2 Cases at each pos, \n1. Not Pick that char in any string\n2. Pick that char, here 2 sub cases\n\ta. Pick in 1st String\n\tb. Pick in 2nd String\n\nbool is | sahilgoyals | NORMAL | 2021-09-12T04:45:53.216784+00:00 | 2021-09-12T05:01:35.831392+00:00 | 935 | false | \n**2 Cases at each pos**, \n1. Not Pick that char in any string\n2. Pick that char, here 2 sub cases\n\ta. Pick in 1st String\n\tb. Pick in 2nd String\n```\nbool isPalin(string &s) {\n\tint i = 0, j = s.length() - 1;\n\twhile(i < j) {\n\t\tif(s[i] != s[j]) return false;\n\t\ti++;\n\t\tj--;\n\t}\n\treturn true;\n}\n\... | 9 | 1 | ['Backtracking', 'C', 'C++'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python DFS solution | python-dfs-solution-by-abkc1221-bco5 | We have 3 possibilities i.e, \n1) not considering the current char for either subsequence \n2) considering it for first one \n3) considering it for second subse | abkc1221 | NORMAL | 2021-09-12T06:08:50.869739+00:00 | 2021-09-12T06:18:36.629351+00:00 | 880 | false | We have 3 possibilities i.e, \n1) not considering the current char for either subsequence \n2) considering it for first one \n3) considering it for second subsequence\n[Follow here](https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences/discuss/1458482/PYTHON-Simple-solution-backtra... | 7 | 0 | ['Depth-First Search', 'Recursion', 'Memoization', 'Python'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ Bitmask DP Time: O(n * 3^n), Space: O(2^n) | c-bitmask-dp-time-on-3n-space-o2n-by-fel-llfr | dp[mask]represent the maximum length of palindrome if we used these characters.\nThere are two cases:\n1) If mask represent a palindrome subsequence, dp[mask]= | felixhuang07 | NORMAL | 2021-09-12T04:00:40.139680+00:00 | 2021-09-12T05:06:51.717071+00:00 | 1,016 | false | ```dp[mask]```represent the maximum length of palindrome if we used these characters.\nThere are two cases:\n1) If mask represent a palindrome subsequence, ```dp[mask]```= the length of that subsequence.\n2) If mask is not a palindrome subsequence, we iterate through all its submasks and find the longest palindrome len... | 6 | 2 | ['Dynamic Programming', 'C', 'Bitmask'] | 4 |
maximum-product-of-the-length-of-two-palindromic-subsequences | MOST SIMPLE KNAPSACK SOLUTION EVER ON INTERNET: most of you thought, must be a hard question but see | most-simple-knapsack-solution-ever-on-in-dwqr | Intuition\njust simple knapsack : make two empty string s1 and s2 and at each element you have three options :\n1. add element to s1 \n2. add element to s2\n3. | aniket_kumar_ | NORMAL | 2024-10-31T09:16:44.422388+00:00 | 2024-10-31T09:16:44.422420+00:00 | 163 | false | # Intuition\njust simple knapsack : make two empty string s1 and s2 and at each element you have three options :\n1. add element to s1 \n2. add element to s2\n3. add element to none of them \n\nat the base case: if(index==s.size()){\n if(s1.size() and s2.size() and ispalindrome(s1) and ispalindrome(s2)){\n ... | 4 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ bitmask, hashmap | c-bitmask-hashmap-by-brandonnjosa4-ahxd | If the string is n chars long, every possible string can be created in a loop from 0-2^n,\nthe same way you generate all subsets. \n\nCreate the strings and rev | BrandonNjosa4 | NORMAL | 2022-07-26T23:57:00.794681+00:00 | 2022-07-26T23:58:03.447275+00:00 | 594 | false | If the string is n chars long, every possible string can be created in a loop from 0-2^n,\nthe same way you generate all subsets. \n\nCreate the strings and reverse them, if its equal its a palidrome.\n\nThe binary version of the numbers in the loop from 0-2^n represents the char positions of each string created, store... | 4 | 0 | ['Bit Manipulation', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Memoized DP | memoized-dp-by-ayushganguli1769-3o5i | We recursively generate two strings string_a , string_b from s.\nIn this quetion at every index i of string s, we have 3 choices:\n1.add s[i] to string_a\n2.add | ayushganguli1769 | NORMAL | 2021-09-12T08:15:28.334291+00:00 | 2021-09-12T08:15:28.334331+00:00 | 356 | false | We recursively generate two strings string_a , string_b from s.\nIn this quetion at every index i of string s, we have 3 choices:\n1.add s[i] to string_a\n2.add s[i] to string_b\n3.Do not add s[i] to string_a or string_b\nWe take max of every 3 choices at every step.\nWhen we i == length of s, we check is string_a and ... | 4 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python - Bruteforce | python-bruteforce-by-ajith6198-k67p | \nclass Solution:\n def maxProduct(self, s: str) -> int:\n subs = []\n n = len(s)\n def dfs(curr, ind, inds):\n if ind == n:\ | ajith6198 | NORMAL | 2021-09-12T04:23:30.847028+00:00 | 2021-09-12T04:35:30.897772+00:00 | 717 | false | ```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n subs = []\n n = len(s)\n def dfs(curr, ind, inds):\n if ind == n:\n if curr == curr[::-1]:\n subs.append((curr, inds))\n return\n dfs(curr+s[ind], ind+1, inds|{ind... | 4 | 0 | ['Python', 'Python3'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Recursion [C++] Explanation | recursion-c-explanation-by-suraj013-fgva | I think the commented code is enough for the explanation.\nfor n <= 12:\n we have 3 option for every position\nso we can simply use recursion with a Time-Comple | suraj013 | NORMAL | 2021-09-12T04:00:45.575824+00:00 | 2021-09-30T11:29:09.312097+00:00 | 419 | false | I think the commented code is enough for the explanation.\nfor n <= 12:\n* we have 3 option for every position\nso we can simply use recursion with a Time-Complexity of **O(n * 3^n)**\n\n* we have maximum of (length(a)+length(b)) length string in any path in the recursion\nso Space Complexity: **O(n)**\n\n**Note**: Don... | 4 | 1 | ['Backtracking', 'Recursion'] | 3 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Simplest Solution With Explanation | simplest-solution-with-explanation-by-ve-qwc4 | \n\n# Code\n\nclass Solution {\npublic:\n // To check whether a string is palindrome or not.\n bool isPalindrome(string s) {\n int n = s.size();\n | Venugopal_Reddy20 | NORMAL | 2023-08-03T13:36:12.823383+00:00 | 2023-08-03T13:36:12.823411+00:00 | 194 | false | \n\n# Code\n```\nclass Solution {\npublic:\n // To check whether a string is palindrome or not.\n bool isPalindrome(string s) {\n int n = s.size();\n for (int i = 0; i < n / 2; i++) {\n if (s[i] != s[n-i-1]) {\n return false;\n }\n }\n return true;\... | 3 | 0 | ['Dynamic Programming', 'Backtracking', 'Recursion', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | bitmask | hashing | C++ | bitmask-hashing-c-by-_shant_11-gu36 | 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 | _shant_11 | NORMAL | 2023-07-24T19:09:09.589817+00:00 | 2023-07-24T19:09:09.589836+00:00 | 322 | 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)$$ --... | 3 | 0 | ['C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ (Backtrack : C++ users, please pass string by reference to PASS) | c-backtrack-c-users-please-pass-string-b-r0l9 | \nclass Solution {\npublic:\nint ans=INT_MIN;\nint maxProduct(string s) \n{\n\t//im trying to get all the disjoint subsequences\n\t\n //the ith char can be i | akshat0610 | NORMAL | 2022-10-21T10:01:41.788149+00:00 | 2022-10-21T10:01:41.788183+00:00 | 884 | false | ```\nclass Solution {\npublic:\nint ans=INT_MIN;\nint maxProduct(string s) \n{\n\t//im trying to get all the disjoint subsequences\n\t\n //the ith char can be in none of the string\n\t//the ith char can be in the first string\n\t//the ith cahr can be in the second string\n\t\n\tint idx=0;\n\tstring s1="";\n\tstring ... | 3 | 0 | ['Dynamic Programming', 'Backtracking', 'Recursion', 'C', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [C++] Simple C++ Code | c-simple-c-code-by-prosenjitkundu760-mtav | \n\n# If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.\n\nclass Solution {\n | _pros_ | NORMAL | 2022-08-16T12:33:40.914456+00:00 | 2022-08-16T12:33:40.914498+00:00 | 573 | false | \n\n# **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\n int n, ans = -1;\n bool isPalindrome(string &p)\n {\n int i = 0, j = p.size()-1;\n while(i <= j)\n {\n if(p[i] == ... | 3 | 1 | ['Dynamic Programming', 'Backtracking', 'Recursion', 'C'] | 2 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Java - Bit Mask | java-bit-mask-by-mathew1234-imxd | \nclass Solution {\n public int maxProduct(String s) {\n HashMap<Integer,Integer> map=new HashMap<>(); // KEY=bit mask , VALUE= length of the string g | Mathew1234 | NORMAL | 2022-08-10T21:38:28.951169+00:00 | 2022-08-10T21:38:28.951235+00:00 | 366 | false | ```\nclass Solution {\n public int maxProduct(String s) {\n HashMap<Integer,Integer> map=new HashMap<>(); // KEY=bit mask , VALUE= length of the string generated from that mask\n int n=s.length();\n for(int mask=0;mask<(1<<n);mask++){// generate bitmask from 1 to 2^n \n String temp=""... | 3 | 0 | ['Bitmask'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Easy C++ Backtracking Solution | easy-c-backtracking-solution-by-harshset-mxh6 | \nclass Solution {\npublic:\n int ans=0;\n bool pal(string &s){\n int l=s.length();\n for(int i=0;i<l-1-i;i++) \n if(s[i]!=s[l-1- | harshseta003 | NORMAL | 2022-07-08T07:17:17.920976+00:00 | 2022-07-08T07:17:17.921012+00:00 | 447 | false | ```\nclass Solution {\npublic:\n int ans=0;\n bool pal(string &s){\n int l=s.length();\n for(int i=0;i<l-1-i;i++) \n if(s[i]!=s[l-1-i]) return false;\n return true;\n }\n void dfs(int curr,string &s1,string &s2,int l, string &s){\n if(curr==l){\n if(pal(s1) ... | 3 | 0 | ['Backtracking', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ || LPS and Brute Force | c-lps-and-brute-force-by-_mhmd_noor-oq5t | upvote if you find it helpful :)\n\nclass Solution {\npublic:\n \n int LPS(string s){ //To find the longest palindrome of a given string\n \n | _mhmd_noor | NORMAL | 2022-06-15T19:52:26.275735+00:00 | 2022-06-15T19:54:06.193553+00:00 | 312 | false | ***upvote if you find it helpful :)***\n```\nclass Solution {\npublic:\n \n int LPS(string s){ //To find the longest palindrome of a given string\n \n if( s.size() == 1 ) return 1;\n int n = s.size();\n int dp[n][n];\n memset(dp,0,sizeof(dp));\n \n for(int i = 0; i... | 3 | 0 | ['Dynamic Programming', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Simple BitMasking, Smart BruteForce 75ms (Java) | simple-bitmasking-smart-bruteforce-75ms-2vx3p | Total possible subsequence n = 1 << string.length()-1\n\nFor each possible subsequence check if the string is palindrome or not. If it\'s palindrome then store | 1_piece | NORMAL | 2021-09-12T05:32:58.860666+00:00 | 2021-09-12T05:39:10.317779+00:00 | 411 | false | Total possible subsequence n = 1 << string.length()-1\n\nFor each possible subsequence check if the string is palindrome or not. If it\'s palindrome then store it in a list. \nNow Iterate through the each pair and check if this pair gives us the maximum result. \n\nBoth pair need to be disjoint to achieve it, we will ... | 3 | 0 | ['Bitmask', 'Java'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [PYTHON] - Simple solution, backtracking✅ | python-simple-solution-backtracking-by-j-hngx | \nclass Solution:\n def maxProduct(self, s: str) -> int:\n self.answer = 0\n \n def dfs(i, word, word2):\n if i >= len(s):\n | just_4ina | NORMAL | 2021-09-12T04:22:47.360283+00:00 | 2021-09-17T23:35:45.486526+00:00 | 876 | false | ```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n self.answer = 0\n \n def dfs(i, word, word2):\n if i >= len(s):\n if word == word[::-1] and word2 == word2[::-1]:\n self.answer = max(len(word) * len(word2), self.answer)\n r... | 3 | 1 | ['Backtracking', 'Recursion', 'Python', 'Python3'] | 4 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python [DP on subsequences] | python-dp-on-subsequences-by-gsan-4qrs | Let dp(sub) be a DP that finds longest palindromic subsequence on a given string sub. Caching intermediate results, this is done in linear time.\n\nWe need to s | gsan | NORMAL | 2021-09-12T04:09:20.283467+00:00 | 2021-09-12T05:28:17.702212+00:00 | 503 | false | Let `dp(sub)` be a DP that finds longest palindromic subsequence on a given string `sub`. Caching intermediate results, this is done in linear time.\n\nWe need to split into all possible subsets, on top of which we can apply DP. There are `2**12 = 4096` such splits at most, so we can cache the substrings.\n\nWe find th... | 3 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [Python] Binary | python-binary-by-davidli-q18f | Binary\n- Step 1: find all palindromic subsequences\n- Step 2: for each pair of palindromic string, if there is no disjoint, calculate the product, update the m | davidli | NORMAL | 2021-09-12T04:02:41.000928+00:00 | 2021-09-12T04:10:28.610755+00:00 | 315 | false | Binary\n- Step 1: find all palindromic subsequences\n- Step 2: for each pair of palindromic string, if there is no disjoint, calculate the product, update the max product value\n\nTips to improve performance:\nUse binary to generate all possible subsequences,\ncache both the binary represent and length of the word\nif ... | 3 | 2 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [C++] Brute force + DP explanation | c-brute-force-dp-explanation-by-code_rel-d3ss | Approach: \nstep1: Generate all subsequence in O(2^n) time (Note: we are storing indices not the characters while generating subsequence)\nstep2: Suppose one of | code_reload | NORMAL | 2021-09-12T04:01:20.244964+00:00 | 2021-09-12T04:10:47.744676+00:00 | 396 | false | **Approach:** \n*step1:* Generate all subsequence in O(2^n) time (Note: we are storing indices not the characters while generating subsequence)\n*step2:* Suppose one of the above subsequence is X. now first check if X is palindrome or not\n*step3:* If X is palindrome. Then get the remaining string i.e by deleting chara... | 3 | 2 | ['Dynamic Programming', 'Recursion', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Backtracking | backtracking-by-astha-poih | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | astha_ | NORMAL | 2025-01-03T08:43:37.204776+00:00 | 2025-01-03T08:43:37.204776+00:00 | 177 | 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
`... | 2 | 0 | ['C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Bit Masking|| Dynamic Programming|| Faster then 94% of C++ users | bit-masking-dynamic-programming-faster-t-ai9i | Complexity\n- Time complexity:O(2^(2N))\n Add your time complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\npublic:\n bool palindrome(string &s) {\n | baarsh2307 | NORMAL | 2024-07-10T09:01:38.661435+00:00 | 2024-07-10T09:01:38.661474+00:00 | 124 | false | # Complexity\n- Time complexity:O(2^(2N))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool palindrome(string &s) {\n int i = 0;\n int j = s.length() - 1;\n while (i < j) {\n if (s[i] != s[j])\n return false;\n ... | 2 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'Bitmask', 'C++'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [Java] DP with clear explanation - O(n*2^n) beats 89% | java-dp-with-clear-explanation-on2n-beat-gxqd | Intuition\nThere are multiple ways to approach this problem:\n1. Find all subsequences, then for any 2, check if they overlap, get get product. Time complexity | zttttt | NORMAL | 2023-04-16T04:30:32.425646+00:00 | 2023-04-16T04:30:32.425689+00:00 | 913 | false | # Intuition\nThere are multiple ways to approach this problem:\n1. Find all subsequences, then for any 2, check if they overlap, get get product. Time complexity O(2^n * 2^n * n) = O(n * 4^n).\n2. Divide s to 2 subsequences - for each character, either assign to seq1, or seq2, or discard. now for seq1 and seq2 check if... | 2 | 0 | ['Dynamic Programming', 'Backtracking', 'Java'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | ✔ C++ Beginner Friendly Recursive Solution ✔ Explained in Detail | c-beginner-friendly-recursive-solution-e-cqn1 | Time Taken : 1732ms Faster than 28.54%\nNOTE : Please someone help me detrmine the time complexity of the given code\n\nAPPROACH :\n Generating all possible pal | ayushman_sinha | NORMAL | 2023-04-14T06:11:57.285078+00:00 | 2023-04-14T06:17:33.468596+00:00 | 1,642 | false | **Time Taken : 1732ms Faster than 28.54%**\nNOTE : Please someone help me detrmine the time complexity of the given code\n\n**APPROACH :**\n* Generating all possible palindromic subsequence of the given string BUT instead of storing the string, I am storing the index of the subsequence thus formed into a vector.\n* For... | 2 | 0 | ['Backtracking', 'Recursion', 'C', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | JAVA || Memoization || Optimal Solution || Easy Soltion | java-memoization-optimal-solution-easy-s-pjnd | \n\nclass Solution {\n \n int ans = 1;\n \n public int maxProduct(String s) {\n \n int[][] dp = new int[s.length() + 1][s.length() + | saswati10 | NORMAL | 2023-01-20T13:55:13.127734+00:00 | 2023-01-20T13:55:13.127788+00:00 | 541 | false | \n```\nclass Solution {\n \n int ans = 1;\n \n public int maxProduct(String s) {\n \n int[][] dp = new int[s.length() + 1][s.length() + 1];\n \n for(int[] d: dp)\n Arrays.fill(d, -1);\n \n int res = solve(s, "", "", 0, dp);\n \n return res;... | 2 | 0 | ['Java'] | 2 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ Backtrack | c-backtrack-by-rishabhsinghal12-8u1o | \nclass Solution {\npublic:\n int ans;\n void dfs(int i, string& s, string& s1, string& s2){\n \n if(i == size(s)){\n \n | Rishabhsinghal12 | NORMAL | 2023-01-07T13:53:22.929548+00:00 | 2023-01-07T13:53:22.929589+00:00 | 484 | false | ```\nclass Solution {\npublic:\n int ans;\n void dfs(int i, string& s, string& s1, string& s2){\n \n if(i == size(s)){\n \n ans = max(ans, (isPal(s1) * isPal(s2)) );\n \n return;\n }\n \n // choose ith character for s1 (not for s2)\n ... | 2 | 0 | ['Backtracking', 'C', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Java Bitmask + HashMap solution | java-bitmask-hashmap-solution-by-aasthas-fqi3 | \nclass Solution {\n\n //using bitmask\n public int maxProduct(String s) {\n \n if(s.length() == 2) {\n return 1;\n }\n \n | aasthasmile | NORMAL | 2022-09-25T23:47:30.469556+00:00 | 2022-09-25T23:47:30.469590+00:00 | 698 | false | ```\nclass Solution {\n\n //using bitmask\n public int maxProduct(String s) {\n \n if(s.length() == 2) {\n return 1;\n }\n \n int n = s.length();\n char[] ch = s.toCharArray();\n \n //bitmask to the length map\n Map<Integer, Integer> bitMasktoLengthMap = new HashMa... | 2 | 0 | ['Bit Manipulation', 'Bitmask', 'Java'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python 3 without Bitmask, Simple Backtracking + DP approach | python-3-without-bitmask-simple-backtrac-zd6x | \nclass Solution:\n def maxProduct(self, s: str) -> int:\n sz, ans, s1, s2 = len(s), 0, \'\', \'\'\n \n @lru_cache(None)\n def so | hemantdhamija | NORMAL | 2022-09-21T11:43:50.052074+00:00 | 2022-09-21T11:43:50.052119+00:00 | 410 | false | ```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n sz, ans, s1, s2 = len(s), 0, \'\', \'\'\n \n @lru_cache(None)\n def solve(i: int, s1: str, s2: str) -> None:\n nonlocal ans, s\n if i >= sz:\n if s1 == s1[::-1] and s2 == s2[::-1]:\n ... | 2 | 0 | ['Dynamic Programming', 'Backtracking', 'Recursion', 'Python'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | c++|bitmasking | cbitmasking-by-priyanshudeep-d7tt | class Solution {\npublic:\n int maxProduct(string s) {\n map m; //\n int n=s.length();\n \n for(int mask=1;mask<(1<<n);ma | priyanshudeep | NORMAL | 2022-07-13T14:34:47.555316+00:00 | 2022-07-13T14:34:47.555373+00:00 | 137 | false | class Solution {\npublic:\n int maxProduct(string s) {\n map<int ,int> m; //<bitmask,length>\n int n=s.length();\n \n for(int mask=1;mask<(1<<n);mask++)\n {\n string subseq="";\n for(int i=0;i<n;i++)\n {\n ... | 2 | 0 | ['Bitmask'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | ✅✅ C++ || BACKTRACKING || EXPLAINED | c-backtracking-explained-by-bhomik23-wbzb | ```\n/\nwe will try out all possibilities through recursion \nbase condition will be where we would have \ntraversed through the whole string , \nthis is the po | bhomik23 | NORMAL | 2022-07-09T09:26:32.334754+00:00 | 2022-08-22T13:14:06.194624+00:00 | 170 | false | ```\n/*\nwe will try out all possibilities through recursion \nbase condition will be where we would have \ntraversed through the whole string , \nthis is the point where we will check whether\nour 2 subsequences are palindromic , and \nif yes , then we will compare the product \nof the lengths of 2 strings with our an... | 2 | 0 | ['Backtracking', 'Recursion', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python | Dynamic Programming | Memoization | python-dynamic-programming-memoization-b-ng4s | \nclass Solution:\n def maxProduct(self, s: str) -> int:\n \n N = len(s)\n memo = {}\n \n def isValidPalindrom(word):\n | k1729g | NORMAL | 2022-04-21T07:33:39.244124+00:00 | 2022-04-21T07:33:39.244153+00:00 | 388 | false | ```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n \n N = len(s)\n memo = {}\n \n def isValidPalindrom(word):\n left, right = 0, len(word)-1\n while (left < right):\n if word[left] != word[right]: return False\n left +=... | 2 | 1 | ['Dynamic Programming', 'Memoization', 'Python'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | All 3 Solutions | Brute | Optimizations | Clean and Concise | Bits | all-3-solutions-brute-optimizations-clea-pyi8 | 1. Using Bits as a visitied array total brute force\n\n\nclass Solution {\npublic:\n bool check(string &s){\n int i=0,j=s.size()-1;\n \n | njcoder | NORMAL | 2022-03-18T11:17:13.398009+00:00 | 2022-03-18T11:22:59.460459+00:00 | 314 | false | #### **1. Using Bits as a visitied array total brute force**\n\n```\nclass Solution {\npublic:\n bool check(string &s){\n int i=0,j=s.size()-1;\n \n while(i < j){\n if(s[i] != s[j]) return false;\n i++;\n j--;\n }\n return true;\n }\n int fun... | 2 | 0 | ['Dynamic Programming', 'Recursion'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | DFS C++| backtracking | dfs-c-backtracking-by-sameer_111-d61c | class Solution {\npublic:\n void dfs(string &s,int i,string &s1,string &s2,int &c){ \n \n\t if(i>=s.size()){\n if(ispalindrome(s1) && ispa | Sameer_111 | NORMAL | 2022-02-12T06:19:16.115705+00:00 | 2022-02-12T06:19:16.115737+00:00 | 198 | false | class Solution {\npublic:\n void dfs(string &s,int i,string &s1,string &s2,int &c){ \n \n\t if(i>=s.size()){\n if(ispalindrome(s1) && ispalindrome(s2)){\n int x = s1.size()*s2.size();\n c = max(x,c);\n }\n return;\n }\n //not pic an... | 2 | 0 | ['Backtracking', 'Depth-First Search', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | My Java Solution using recursion | my-java-solution-using-recursion-by-vroh-5m59 | \nclass Solution {\n \n private int maxProduct = -1;\n \n public int maxProduct(String s) {\n if (s == null || s.length() <= 1) {\n | vrohith | NORMAL | 2021-09-28T18:38:55.727832+00:00 | 2021-09-28T18:38:55.727877+00:00 | 360 | false | ```\nclass Solution {\n \n private int maxProduct = -1;\n \n public int maxProduct(String s) {\n if (s == null || s.length() <= 1) {\n return 0;\n }\n int length = s.length();\n if (length == 1) {\n return 1;\n }\n List<Character> word1 = new A... | 2 | 1 | ['Recursion', 'Java'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | c++ backtracking solution | c-backtracking-solution-by-divkr98-te0e | \n\n#include<bits/stdc++.h>\nusing namespace std;\nint ans;\n\nbool ispal(string &s)\n{\n int i = 0 , j = s.length() - 1;\n while(i < j){\n if(s[i] | divkr98 | NORMAL | 2021-09-26T12:52:04.331586+00:00 | 2021-09-26T12:52:04.331621+00:00 | 264 | false | ```\n\n#include<bits/stdc++.h>\nusing namespace std;\nint ans;\n\nbool ispal(string &s)\n{\n int i = 0 , j = s.length() - 1;\n while(i < j){\n if(s[i] != s[j]) return false;\n ++i;\n --j;\n }\n return true;\n}\n\nvoid solve(int index , string &s , string &s1, string &s2)\n{\n\n /// a... | 2 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Backtracking | explained solution | c++ | backtracking-explained-solution-c-by-cra-jn7b | just see the constraint for this question its very small so this signifies that this will be a backtracking question.\n\nlets assume my s1 will have the 1st pal | crabbyD | NORMAL | 2021-09-14T19:37:25.867016+00:00 | 2021-09-14T19:37:25.867049+00:00 | 151 | false | just see the constraint for this question its very small so this signifies that this will be a backtracking question.\n\nlets assume my s1 will have the 1st palindrome string and s2 will have the second one.\n\ni am finding the max of a,b,c where a denotes when i am not not adding any values.\nb denotes i am pushing va... | 2 | 0 | ['Backtracking', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | a few solutions | a-few-solutions-by-claytonjwong-p7wm | Let A and B be the first and second candidate palindrome strings correspondingly. Perform DFS + BT considering all possibilities for each character s[i]:\n\n1. | claytonjwong | NORMAL | 2021-09-13T13:35:11.381646+00:00 | 2021-09-14T22:35:55.331352+00:00 | 57 | false | Let `A` and `B` be the first and second candidate palindrome strings correspondingly. Perform DFS + BT considering all possibilities for each character `s[i]`:\n\n1. `s[i]` is included in `A`\n2. `s[i]` is included in `B`\n3. `s[i]` is *not* included in `A` or `B`\n\n---\n\n*Kotlin*\n```\nclass Solution {\n fun max... | 2 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ || Recursion + Backtracking || Easy To Understand ✔ | c-recursion-backtracking-easy-to-underst-p06c | \nclass Solution {\npublic:\n\tint ans = 0;\n\tint n;\n\t//function for checking is given string is Palindrome\n\tbool palindrome(string s)\n\t{\n\t\tint i = 0; | AJAY_MAKVANA | NORMAL | 2021-09-12T09:56:17.313587+00:00 | 2021-09-13T07:33:42.926834+00:00 | 147 | false | ```\nclass Solution {\npublic:\n\tint ans = 0;\n\tint n;\n\t//function for checking is given string is Palindrome\n\tbool palindrome(string s)\n\t{\n\t\tint i = 0;\n\t\tint j = s.size() - 1;\n\t\twhile (i <= j)\n\t\t{\n\t\t\tif (s[i++] != s[j--])\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\... | 2 | 0 | ['Backtracking', 'Recursion', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Java Solution - Standard Recursion and Backtracking | java-solution-standard-recursion-and-bac-j3h1 | Idea\nFirst you need to find the first pallin subsequence string then you need to remove that string from the original string and finding the another pallin sub | pgthebigshot | NORMAL | 2021-09-12T04:46:49.961744+00:00 | 2021-09-12T04:59:21.312433+00:00 | 277 | false | **Idea**\nFirst you need to find the first pallin subsequence string then you need to remove that string from the original string and finding the another pallin subsequence string.\n```\nclass Solution {\n\tint max=Integer.MIN_VALUE;\n\tvoid recur(String str,int n,int ind,String s,List<Integer> list)\n\t{\n\t\tif(ind==... | 2 | 1 | ['Backtracking', 'Java'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Dp in Python | dp-in-python-by-pisces311-8jo1 | We may use dp to enumerate the first palindromic sequence. Since the maximum length of the original string is only 12 - the iteration goes up to 2**12=4096 time | Pisces311 | NORMAL | 2021-09-12T04:43:56.590720+00:00 | 2021-09-12T04:58:51.201943+00:00 | 187 | false | We may use dp to enumerate the first palindromic sequence. Since the maximum length of the original string is only 12 - the iteration goes up to `2**12=4096` times. Actually, small sized problem should always remind you to think about brute force.\n\nAfter that, just try to find the longest palindromic subsequence in t... | 2 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Simple Java DP Solution - Top Down Recursion | simple-java-dp-solution-top-down-recursi-m216 | \nclass Solution {\n public int maxProduct(String s) {\n return maxProduct(s, 0, "","");\n }\n Map<String, Integer> dp = new HashMap<>();\n p | vathsalyabhupathi | NORMAL | 2021-09-12T04:23:48.037141+00:00 | 2021-09-12T04:23:48.037168+00:00 | 310 | false | ```\nclass Solution {\n public int maxProduct(String s) {\n return maxProduct(s, 0, "","");\n }\n Map<String, Integer> dp = new HashMap<>();\n public int maxProduct(String s, int ci, String s1, String s2) {\n int max = 0;\n String key = ci+"_"+s1 +"_"+s2;\n \n if(dp.contai... | 2 | 0 | [] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [C++] Backtracking Solution | c-backtracking-solution-by-manishbishnoi-4ipn | \nclass Solution {\n int ans;\n // Check for palindrome\n bool isPalindrome(string& temp){\n int i=0,j = temp.length() - 1;\n while(i<j){ | manishbishnoi897 | NORMAL | 2021-09-12T04:16:00.742005+00:00 | 2021-09-12T04:20:14.720798+00:00 | 156 | false | ```\nclass Solution {\n int ans;\n // Check for palindrome\n bool isPalindrome(string& temp){\n int i=0,j = temp.length() - 1;\n while(i<j){\n if(temp[i]!=temp[j]){\n return false;\n }\n i++,j--;\n }\n return true;\n }\n \n vo... | 2 | 1 | ['Backtracking', 'C'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Python Simple Soln(Brute Force) | python-simple-solnbrute-force-by-atul_ii-njyj | \n def maxProduct(self, s: str) -> int:\n def largestP(s):\n n = len(s)\n dp = [1] * n\n for j in range(1, len(s)):\n | atul_iitp | NORMAL | 2021-09-12T04:06:24.194510+00:00 | 2021-09-12T06:23:23.661225+00:00 | 143 | false | ```\n def maxProduct(self, s: str) -> int:\n def largestP(s):\n n = len(s)\n dp = [1] * n\n for j in range(1, len(s)):\n pre = dp[j]\n for i in reversed(range(0, j)):\n tmp = dp[i]\n if s[i] == s[j]:\n ... | 2 | 1 | ['Dynamic Programming', 'Iterator'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Easy brute force solution in c++ | easy-brute-force-solution-in-c-by-adithy-kh9d | \n\n\n\nclass Solution {\npublic:\n bool isPalindrome(string str)\n {\n // Start from leftmost and rightmost corners of str\n int l = 0;\n | adithya_u_bhat | NORMAL | 2021-09-12T04:06:20.115534+00:00 | 2021-09-12T04:10:17.219389+00:00 | 92 | false | \n\n```\n\nclass Solution {\npublic:\n bool isPalindrome(string str)\n {\n // Start from leftmost and rightmost corners of str\n int l = 0;\n int h = str.size()-1;\n\n // Keep comparing characters while they are same\n while (h > l)\n {\n if (str[l++] != str[h-... | 2 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Java Solution with Explanation | java-solution-with-explanation-by-goals_-zfmp | Intuition\nRecursion to get all possible subsequence for consideration\nSimilar working as- all_possible_subsequence_of_string_problem\n\n# Approach\n1) conside | Goals_7 | NORMAL | 2024-09-04T07:29:17.928396+00:00 | 2024-09-04T07:29:17.928428+00:00 | 175 | false | # Intuition\nRecursion to get all possible subsequence for consideration\nSimilar working as- [all_possible_subsequence_of_string_problem](https://takeuforward.org/data-structure/power-set-print-all-the-possible-subsequences-of-the-string/)\n\n# Approach\n1) consider current char for S1\n2) consider current char for S2... | 1 | 0 | ['Recursion', 'Java'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Easy to understand Solution | Bitmask | Brute force | easy-to-understand-solution-bitmask-brut-nmox | Intuition\nThe problem is asking for the maximum product of the lengths of two non-overlapping palindromic subsequences. The key observation is that palindromic | Harsh-1510 | NORMAL | 2024-08-23T07:36:04.140967+00:00 | 2024-08-23T07:36:04.141001+00:00 | 24 | false | # Intuition\nThe problem is asking for the maximum product of the lengths of two non-overlapping palindromic subsequences. The key observation is that palindromic subsequences can be generated using bitmasks, and if we check for all possible pairs of subsequences, we can identify those that are non-overlapping and have... | 1 | 0 | ['Hash Table', 'Bitmask', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Well defined with bitmask. Beats 100%. O(N^2 * 2^N). | well-defined-with-bitmask-beats-100-on2-xyn0h | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nFind all subpalindromes | alexanderwsz | NORMAL | 2024-07-03T11:53:02.562963+00:00 | 2024-07-03T21:22:37.689483+00:00 | 109 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFind all subpalindromes.\nTraverse subpalindromes\n---- if pair.isDisjoint\n-------- currentProduct = length1 * length2\n-------- currentMax = (maxProduct, currentProd... | 1 | 0 | ['Swift'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | MOST OPTIMIZED C++ SOLUTION | most-optimized-c-solution-by-tin_le-e9vd | 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 | tin_le | NORMAL | 2024-04-17T00:31:34.417217+00:00 | 2024-04-17T00:31:34.417239+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)$$ --... | 1 | 0 | ['C++'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Explained approach with time and space complexities. 🔥 | explained-approach-with-time-and-space-c-v1vj | Intuition \n Describe your first thoughts on how to solve this problem. \nUtilize bitmasking to efficiently generate all possible subsequences of the string and | sirsebastian5500 | NORMAL | 2024-02-27T03:03:19.535262+00:00 | 2024-02-27T03:03:19.535292+00:00 | 165 | false | # Intuition \n<!-- Describe your first thoughts on how to solve this problem. -->\nUtilize bitmasking to efficiently generate all possible subsequences of the string and to verify if two strings are disjoint.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nGenerate all subsequences using bitmaskin... | 1 | 0 | ['Python3'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Simple find all subarray approach | simple-find-all-subarray-approach-by-aan-rjgk | Intuition\nInstead of storing the char we are storing the indices of all subarray\nIt will be easier to find duplicate. if we store char it can be duplicate\n\n | aanya_969 | NORMAL | 2024-01-11T14:11:35.463303+00:00 | 2024-01-11T14:11:35.463327+00:00 | 14 | false | # Intuition\nInstead of storing the char we are storing the indices of all subarray\nIt will be easier to find duplicate. if we store char it can be duplicate\n\n# Complexity\n- Time complexity:\nO(2^n * n^2)\n\n- Space complexity:\n(2^n * n)\n\n# Code\n```\nclass Solution {\npublic:\n vector<vector<int>>allSubarr;\... | 1 | 0 | ['C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Bitmask approach in TypeScript | bitmask-approach-in-typescript-by-teoyuq-ryju | Approach\n1. Use bit mask to get all possible subsequences.\n2. If subsequence is palindrome, add [bitmask, length] pair to array.\n3. Iterate through all pairs | teoyuqi | NORMAL | 2024-01-01T12:11:26.269036+00:00 | 2024-01-01T12:11:26.269069+00:00 | 132 | false | # Approach\n1. Use bit mask to get all possible subsequences.\n2. If subsequence is palindrome, add `[bitmask, length]` pair to array.\n3. Iterate through all pairs in array. If two bitmasks are disjoint, `(bitmask1 & bitmask2) === 0`.\n4. Return max length product.\n\n# Complexity\nIn worst case, we have 2^n `[subseq,... | 1 | 0 | ['Bit Manipulation', 'Bitmask', 'TypeScript'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | DP || Bitmask || Recurssion || C++|| ✅94.18% Beats✅|| | dp-bitmask-recurssion-c-9418-beats-by-fi-ho0j | Intuition\n Describe your first thoughts on how to solve this problem. \n- Initially check all LCS in the string.\n- Create a mask of every LCS possible.\n- Usi | FishBum | NORMAL | 2023-09-28T09:37:20.193627+00:00 | 2023-09-28T09:37:20.193653+00:00 | 88 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Initially check all LCS in the string.\n- Create a mask of every LCS possible.\n- Using the mask take the LCS of unset indexes.\n- Then take the maximum of the product of both for each LCS. \n\n# Code\n```\nclass Solution {\npublic:\n ... | 1 | 0 | ['Dynamic Programming', 'Backtracking', 'Recursion', 'Bitmask', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Easy Detailed Sol || C++ Backtracking | easy-detailed-sol-c-backtracking-by-yeah-blc0 | Intuition\nas the constraints are too small we can look for generating all possible subsequences and then check whether they are distinct or not and calculate t | yeah_boi123 | NORMAL | 2023-07-13T11:14:52.043133+00:00 | 2023-07-13T11:14:52.043158+00:00 | 55 | false | # Intuition\nas the constraints are too small we can look for generating all possible subsequences and then check whether they are distinct or not and calculate the answer \n\n# Approach\nso what i did was to first i made all subsequences using bitmask and then i pushed the bitmask of the string which is a palindrome i... | 1 | 0 | ['Backtracking', 'Bit Manipulation', 'Bitmask', 'C++'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Javascript with bit mask | javascript-with-bit-mask-by-vwxyz-pefe | 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 | vwxyz | NORMAL | 2023-04-07T09:31:33.849757+00:00 | 2023-04-07T09:31:33.849791+00:00 | 124 | 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)$$ --... | 1 | 0 | ['JavaScript'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | Brute Force Appro | brute-force-appro-by-sanjeevkrpathak-8isx | \n\n# Code\n\nclass Solution:\n def maxProduct(self, s: str) -> int:\n N,pali = len(s),{} # bitmask = length\n\n for mask in range(1,1<<N): # 1 | sanjeevkrpathak | NORMAL | 2023-03-22T18:17:32.284176+00:00 | 2023-03-22T18:17:32.284218+00:00 | 225 | false | \n\n# Code\n```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n N,pali = len(s),{} # bitmask = length\n\n for mask in range(1,1<<N): # 1 << N == 2**N\n subseq = ""\n for i in range(N):\n if mask & (1<<i):\n subseq+=s[i]\n\n if... | 1 | 0 | ['Python3'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | [python 3] Bitmask | python-3-bitmask-by-gabhay-so81 | \tclass Solution:\n\t\tdef maxProduct(self, s: str) -> int:\n\t\t\tdef create_string(v):\n\t\t\t\tres=[]\n\t\t\t\tfor i in range(n):\n\t\t\t\t\tif 1<<i&v:\n\t\t | gabhay | NORMAL | 2022-11-24T11:30:40.735651+00:00 | 2022-11-24T11:30:40.735691+00:00 | 108 | false | \tclass Solution:\n\t\tdef maxProduct(self, s: str) -> int:\n\t\t\tdef create_string(v):\n\t\t\t\tres=[]\n\t\t\t\tfor i in range(n):\n\t\t\t\t\tif 1<<i&v:\n\t\t\t\t\t\tres.append(s[i])\n\t\t\t\tif res==res[::-1]:\n\t\t\t\t\tpal[v]=len(res)\n\t\t\tpal=dict()\n\t\t\tn=len(s)\n\t\t\tfor i in range(1,pow(2,n)):\n\t\t\t\tcr... | 1 | 0 | ['Bitmask', 'Python3'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ || NOT sure How DP is used in my soln. | c-not-sure-how-dp-is-used-in-my-soln-by-1nvgd | TC: O( 3 ^N )\nSC: O(1) + Auxiliary Stack Space O(N)\n\nclass Solution {\npublic:\n bool isPalindrome(string &str){\n int i=0,j=str.size()-1;\n | rohitraj13may1998 | NORMAL | 2022-08-31T18:57:15.552994+00:00 | 2022-08-31T18:57:15.553040+00:00 | 527 | false | TC: O( 3 ^N )\nSC: O(1) + Auxiliary Stack Space O(N)\n```\nclass Solution {\npublic:\n bool isPalindrome(string &str){\n int i=0,j=str.size()-1;\n while(i<j){\n if(str[i]!=str[j])\n return false;\n i++;\n j--;\n }\n return true;\n }\n ... | 1 | 0 | ['Backtracking', 'C++'] | 1 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++||Backtracking|| Easy to Understand | cbacktracking-easy-to-understand-by-retu-tfkp | ```\nclass Solution {\npublic:\n long long res;\n bool ispal(string &s)\n {\n int start=0,end=s.size()-1;\n while(start=s.size())\n | return_7 | NORMAL | 2022-07-21T15:29:24.161905+00:00 | 2022-07-21T15:29:24.161948+00:00 | 118 | false | ```\nclass Solution {\npublic:\n long long res;\n bool ispal(string &s)\n {\n int start=0,end=s.size()-1;\n while(start<end)\n {\n if(s[start]!=s[end])\n return false;\n start++;\n end--;\n }\n return true;\n }\n void back... | 1 | 0 | ['Backtracking', 'C'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | eayc C++ code o(n^2*2^n) | eayc-c-code-on22n-by-gurmeet2000-30xp | \n int maxProduct(string s) {\n int n=s.length();\n int ans=0;\n for(int k=1;k<pow(2,n)-1;k++)\n {\n string unused="";\n | gurmeet2000 | NORMAL | 2022-06-20T07:17:52.407686+00:00 | 2022-06-20T07:22:39.086767+00:00 | 160 | false | ```\n int maxProduct(string s) {\n int n=s.length();\n int ans=0;\n for(int k=1;k<pow(2,n)-1;k++)\n {\n string unused="";\n string used="";\n for(int j=0;j<n;j++)\n {\n if(k&1<<j)\n {\n used+=s[j];\n... | 1 | 0 | ['Dynamic Programming', 'Bitmask'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | c++|dp with bitamask +longest palindromic subsequence | cdp-with-bitamask-longest-palindromic-su-jo8m | \nclass Solution {\npublic:\n bool check_palindrom(int m,string s){\n int i=0;\n string temp="";\n while(m>0){\n if(m&1){\n | deepak_pal8790 | NORMAL | 2022-06-09T03:29:10.082508+00:00 | 2022-06-09T03:29:37.836716+00:00 | 138 | false | ```\nclass Solution {\npublic:\n bool check_palindrom(int m,string s){\n int i=0;\n string temp="";\n while(m>0){\n if(m&1){\n temp+=s[i];\n }\n m=m>>1;\n i++;\n }\n int start=0;\n int end=temp.length()-1;\n w... | 1 | 0 | ['Dynamic Programming', 'Bitmask'] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ || Bactracking || Easy to understand | c-bactracking-easy-to-understand-by-abhi-kr6t | \nint ans=0;\n bool isPal(string& s)\n {\n int i=0,j=s.length()-1;\n while(i<=j)\n {\n if(s[i]!=s[j])\n return | abhishek_iiitp | NORMAL | 2022-05-20T05:30:14.714556+00:00 | 2022-05-20T05:30:14.714602+00:00 | 112 | false | ```\nint ans=0;\n bool isPal(string& s)\n {\n int i=0,j=s.length()-1;\n while(i<=j)\n {\n if(s[i]!=s[j])\n return false;\n i++;\n j--;\n }\n return true;\n }\n void helper(string& s,string& s1,string& s2,int i)\n {\n if... | 1 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | C++ || EASY TO UNDERSTAND || Simple Solution Using BackTracking | c-easy-to-understand-simple-solution-usi-y79o | \nclass Solution {\npublic:\n int ans=0;\n bool isPalin(string& s)\n {\n int i=0,j=s.length()-1;\n while(i<=j)\n {\n if | aarindey | NORMAL | 2022-04-08T11:59:39.734908+00:00 | 2022-04-08T11:59:39.734936+00:00 | 105 | false | ```\nclass Solution {\npublic:\n int ans=0;\n bool isPalin(string& s)\n {\n int i=0,j=s.length()-1;\n while(i<=j)\n {\n if(s[i]!=s[j])\n return false;\n i++;\n j--;\n }\n return true;\n }\n void dfs(string& s,string& s1,string... | 1 | 0 | [] | 0 |
maximum-product-of-the-length-of-two-palindromic-subsequences | JS - slow but simple (without bitmask) | js-slow-but-simple-without-bitmask-by-ge-t2yg | Only possible since s.length <= 12 and we can basically check every possible variant.\n\nBased on this Python solution:\nhttps://leetcode.com/problems/maximum-p | georgiiperepechko | NORMAL | 2022-03-20T15:11:15.402017+00:00 | 2022-03-20T15:11:58.657100+00:00 | 199 | false | Only possible since s.length <= 12 and we can basically check every possible variant.\n\nBased on this Python solution:\nhttps://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences/discuss/1458751/Python-DFS-solution\n\n```\nconst isPalindrome = (str) => {\n for (let i = 0, j = str.le... | 1 | 0 | ['JavaScript'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.