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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
string-without-aaa-or-bbb | C++ 6 line Easy Code || 100% | c-6-line-easy-code-100-by-code_1501-7awu | *Please upvote me :)*\n\n\n string strWithout3a3b(int A, int B) {\n string res;\n while (A && B) {\n if (A > B) {\n r | code_1501 | NORMAL | 2022-02-28T04:59:58.899557+00:00 | 2022-02-28T04:59:58.899605+00:00 | 902 | false | ****Please upvote me :)****\n\n```\n string strWithout3a3b(int A, int B) {\n string res;\n while (A && B) {\n if (A > B) {\n res += "aab";\n A--;\n } else if (B > A) {\n res += "bba";\n B--;\n } else {\n ... | 14 | 0 | ['C'] | 1 |
string-without-aaa-or-bbb | [Java] Simple Greedy | java-simple-greedy-by-gcarrillo-dl9d | \n\nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder ans = new StringBuilder();\n int size = A+B;\n int a | gcarrillo | NORMAL | 2019-01-27T04:02:23.046834+00:00 | 2019-01-27T04:02:23.046881+00:00 | 1,163 | false | \n```\nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder ans = new StringBuilder();\n int size = A+B;\n int a = 0, b = 0;\n for(int i = 0; i < size; i++){\n if((A >= B && a != 2) || b == 2){ \n ans.append("a");\n A--;... | 12 | 1 | [] | 4 |
string-without-aaa-or-bbb | Greedy Approach! || Beats 100%|| C++|| Easy to understand Approach | greedy-approach-beats-100-c-easy-to-unde-eq7j | About the questionThis is a fundamental yet frequently asked problem in FAANG-style interviews. The problem statement indirectly relates to Theory of Computatio | Manthu01 | NORMAL | 2025-03-16T11:21:02.241422+00:00 | 2025-03-16T11:21:02.241422+00:00 | 96 | false | 
# About the question
This is a fundamental yet frequently asked problem in FAANG-style interviews. The problem statement indirectly relates to Theory of Computation (TOC) concepts, so anyone familiar wi... | 11 | 0 | ['String', 'Greedy', 'C++'] | 2 |
string-without-aaa-or-bbb | C++ || Easy to understand || 100% fast✔ | c-easy-to-understand-100-fast-by-nitinsi-fk3s | \n\n# Code\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans=""; //String to store the answer\n int counta=0,co | NitinSingh77 | NORMAL | 2023-03-19T13:57:57.738047+00:00 | 2023-03-19T13:57:57.738092+00:00 | 1,153 | false | \n\n# Code\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans=""; //String to store the answer\n int counta=0,countb=0; // Counter to check that a and b should not be greater than two;\n int total=a+b; //No of times the loop will run;\n for(int i=... | 9 | 0 | ['C++'] | 0 |
string-without-aaa-or-bbb | My Java Solution with the basic idea as comments | my-java-solution-with-the-basic-idea-as-b0g35 | \nclass Solution {\n public String strWithout3a3b(int a, int b) {\n StringBuilder sb = new StringBuilder();\n while (a > 0 || b > 0) {\n | vrohith | NORMAL | 2021-04-25T11:14:48.438369+00:00 | 2021-04-25T11:14:48.438403+00:00 | 1,120 | false | ```\nclass Solution {\n public String strWithout3a3b(int a, int b) {\n StringBuilder sb = new StringBuilder();\n while (a > 0 || b > 0) {\n String s = sb.toString();\n // if we have aa as the last 2 characters, then the next one is b\n if (s.endsWith("aa")) {\n ... | 9 | 0 | ['String', 'Java'] | 2 |
string-without-aaa-or-bbb | A simple Java recursion solution | a-simple-java-recursion-solution-by-yili-7sse | \nclass Solution {\n StringBuilder sb = new StringBuilder();\n public String strWithout3a3b(int A, int B) {\n if (A == 0 || B == 0) {\n | yilin_10 | NORMAL | 2019-06-18T17:07:03.643412+00:00 | 2019-06-19T04:39:25.373729+00:00 | 695 | false | ```\nclass Solution {\n StringBuilder sb = new StringBuilder();\n public String strWithout3a3b(int A, int B) {\n if (A == 0 || B == 0) {\n while (A-- > 0) sb.append(\'a\');\n while (B-- > 0) sb.append(\'b\');\n } else if (A == B) {\n sb.append("ab");\n str... | 8 | 1 | ['Recursion', 'Java'] | 3 |
string-without-aaa-or-bbb | simple C++ solution 100% faster | simple-c-solution-100-faster-by-anoushka-uh50 | \nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n \n string ans="";\n int ca=0,cb=0; //maintain count of last conti | anoushkas23 | NORMAL | 2021-12-27T14:45:54.831010+00:00 | 2021-12-27T14:45:54.831047+00:00 | 672 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n \n string ans="";\n int ca=0,cb=0; //maintain count of last continuously appended a\'s or b\'s\n \n while(a>0 || b>0)\n {\n if(a>=b && ca<2 || (b>=a && cb>=2))\n {\n ... | 6 | 0 | ['C', 'C++'] | 0 |
string-without-aaa-or-bbb | C++ Simple Logic Best Code :) | c-simple-logic-best-code-by-sayan_11_mai-jz3e | \n\nclass Solution\n{\npublic:\n string strWithout3a3b(int a, int b)\n {\n\n string s;\n if (a > b)\n {\n while (a != 0)\n | sayan_11_maitra | NORMAL | 2022-02-24T17:31:33.545326+00:00 | 2022-02-24T17:31:33.545379+00:00 | 332 | false | ```\n\nclass Solution\n{\npublic:\n string strWithout3a3b(int a, int b)\n {\n\n string s;\n if (a > b)\n {\n while (a != 0)\n {\n s += \'a\';\n a--;\n\n if (a > b)\n {\n s += \'a\';\n ... | 5 | 1 | [] | 0 |
string-without-aaa-or-bbb | [C++] Faster Than 100% | Greedy solution | clean and concise | c-faster-than-100-greedy-solution-clean-q689y | Please upvote if it helps!\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans="";\n int n=a+b;\n int x=0, | somurogers | NORMAL | 2021-06-22T02:27:15.176686+00:00 | 2021-06-22T02:27:15.176726+00:00 | 382 | false | Please upvote if it helps!\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans="";\n int n=a+b;\n int x=0, y=0;\n for(int i=0;i<n;i++)\n {\n if((a>=b && x!=2) || (y==2 && a>0))\n {\n x++;a--;y=0;\n ... | 5 | 1 | ['Greedy', 'C', 'C++'] | 1 |
string-without-aaa-or-bbb | simple python solution | simple-python-solution-by-ashmit007-3etl | \nclass Solution(object):\n def strWithout3a3b(self, A, B):\n if A == 0 or B == 0:\n return \'a\'*A +\'b\'*B\n elif A>B:\n | ashmit007 | NORMAL | 2019-02-05T11:24:54.284999+00:00 | 2019-02-05T11:24:54.285064+00:00 | 478 | false | ```\nclass Solution(object):\n def strWithout3a3b(self, A, B):\n if A == 0 or B == 0:\n return \'a\'*A +\'b\'*B\n elif A>B:\n return \'aab\' + self.strWithout3a3b(A-2, B-1)\n elif B>A:\n return self.strWithout3a3b(A-1, B-2)+ \'abb\'\n else:\n re... | 5 | 0 | [] | 1 |
string-without-aaa-or-bbb | C++ || 100% BEATS | c-100-beats-by-ganeshkumawat8740-68gd | Code\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans = "";\n while(a >= 1 && b>=1){\n if(a-b>=1){\ | ganeshkumawat8740 | NORMAL | 2023-06-26T02:53:10.007005+00:00 | 2023-06-26T02:53:10.007025+00:00 | 666 | false | # Code\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans = "";\n while(a >= 1 && b>=1){\n if(a-b>=1){\n ans = ans+"aab";\n a-=2;b--;\n }else if(a==b){\n ans += "ab";\n a--;b--;\n ... | 4 | 0 | ['String', 'Greedy', 'C++'] | 0 |
string-without-aaa-or-bbb | EASY SOLUTION IN JAVA | easy-solution-in-java-by-kumarakash-ae0c | class Solution {\n public String strWithout3a3b(int a, int b) {\n String str="";\n \n while(a!=b)\n {\n if(a> | kumarakash | NORMAL | 2022-08-25T17:57:19.608948+00:00 | 2022-08-25T17:57:19.608991+00:00 | 873 | false | class Solution {\n public String strWithout3a3b(int a, int b) {\n String str="";\n \n while(a!=b)\n {\n if(a>b)\n {\n str=str+"aa";\n str=str+"b";\n a=a-2;\n b--;\n if(b==0||a==... | 4 | 0 | ['Java'] | 0 |
string-without-aaa-or-bbb | Simple Math Problem Without Recursion | simple-math-problem-without-recursion-by-sbau | This problem can easily be done without recursion.\nSuppose A > B, it can be splitted into two situations.\n1. When A >= 2 * B, the result string can be constru | dentiny | NORMAL | 2019-07-27T15:37:55.478554+00:00 | 2019-07-27T15:37:55.478586+00:00 | 609 | false | This problem can easily be done without recursion.\nSuppose `A > B`, it can be splitted into two situations.\n1. When `A >= 2 * B`, the result string can be constructed with `B "aab"`; since the last character for the current string mush be` \'b\'`, it can be followed with `A - B \'a\'`.\n1. When `B < A < 2 * B`, the r... | 4 | 1 | ['Math', 'C++', 'Python3'] | 1 |
string-without-aaa-or-bbb | Simple Greedy method(faster than 100.00% of Java online submissions) | simple-greedy-methodfaster-than-10000-of-uswu | Greedy by the number of \'a\' and \'b\';\nRuntime: 3 ms, faster than 100.00% of Java online submissions for String Without AAA or BBB.\n\n\n\nclass Solution {\n | lotay | NORMAL | 2019-03-07T13:59:11.018629+00:00 | 2019-03-07T13:59:11.018661+00:00 | 398 | false | Greedy by the number of \'a\' and \'b\';\nRuntime: 3 ms, faster than 100.00% of Java online submissions for String Without AAA or BBB.\n\n```\n\nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder sb = new StringBuilder();\n while(A>B && B > 0){\n sb.append("aab")... | 4 | 0 | [] | 0 |
string-without-aaa-or-bbb | String Without AAA or BBB-Easy Python solution beats 96% | string-without-aaa-or-bbb-easy-python-so-3e3x | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | koppuhemanthsaikumar123 | NORMAL | 2025-01-10T04:35:53.940593+00:00 | 2025-01-10T04:35:53.940593+00:00 | 163 | 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
`... | 3 | 0 | ['String', 'Greedy', 'Python', 'Python3'] | 0 |
string-without-aaa-or-bbb | 0 ms runtime well commented | 0-ms-runtime-well-commented-by-shristha-zgv2 | \n\n# Code\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n\n //idea is we count how many continous a\'s & b\'s appended if if b | Shristha | NORMAL | 2023-01-31T15:11:06.076690+00:00 | 2023-01-31T15:11:06.076728+00:00 | 325 | false | \n\n# Code\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n\n //idea is we count how many continous a\'s & b\'s appended if if becomes we change next letter to be appended\n \n string res="";\n int la=0,lb=0;\n while(a>0 || b>0){\n\n if((a>=b && ... | 3 | 0 | ['Greedy', 'C++'] | 0 |
string-without-aaa-or-bbb | faster than 94.02% solutions (one liner easy solution) | faster-than-9402-solutions-one-liner-eas-qlwq | \nclass Solution:\n def strWithout3a3b(self, A: int, B: int) -> str:\n return [\'a\']*A + [\'b\']*B\n | sarthak2000 | NORMAL | 2020-12-02T14:33:00.246971+00:00 | 2020-12-02T14:33:00.247014+00:00 | 128 | false | ```\nclass Solution:\n def strWithout3a3b(self, A: int, B: int) -> str:\n return [\'a\']*A + [\'b\']*B\n``` | 3 | 2 | [] | 0 |
string-without-aaa-or-bbb | Recursive JavaScript Solution | recursive-javascript-solution-by-_kamal_-chmt | \n/**\n * @param {number} A\n * @param {number} B\n * @return {string}\n */\nvar strWithout3a3b = function(A, B) {\n if (A === 0) return "b".repeat(B);\n | _kamal_jain | NORMAL | 2020-08-17T17:29:43.941339+00:00 | 2020-08-17T17:29:43.941388+00:00 | 349 | false | ```\n/**\n * @param {number} A\n * @param {number} B\n * @return {string}\n */\nvar strWithout3a3b = function(A, B) {\n if (A === 0) return "b".repeat(B);\n if (B === 0) return "a".repeat(A);\n if (A === B) return "ab" + strWithout3a3b(A - 1, B - 1);\n if (A > B) return "aab" + strWithout3a3b(A - 2, B - 1);... | 3 | 0 | ['Recursion', 'JavaScript'] | 4 |
string-without-aaa-or-bbb | [Python] Very easy 4 line solution without loop and recursion beats 100% | python-very-easy-4-line-solution-without-xe9t | \nclass Solution:\n def strWithout3a3b(self, A, B, a = \'a\', b = \'b\'):\n if A < B:\n A, B = B, A\n a, b = b, a\n retur | asukaev | NORMAL | 2019-02-01T05:34:38.473604+00:00 | 2019-02-01T05:34:38.473674+00:00 | 152 | false | ```\nclass Solution:\n def strWithout3a3b(self, A, B, a = \'a\', b = \'b\'):\n if A < B:\n A, B = B, A\n a, b = b, a\n return ((a + a + b) * (A - B) + (a + b) * (A - 2 * (A - B)))[:A + B]\n``` | 3 | 0 | [] | 0 |
string-without-aaa-or-bbb | Java easy understand with comment | java-easy-understand-with-comment-by-zez-1dj6 | \nclass Solution {\n public String strWithout3a3b(int a, int b) {\n // if a > b, swap a and b\n if (b > a) \n\t\t\treturn helper(a, b);\n | zezecool | NORMAL | 2019-01-27T04:25:32.942861+00:00 | 2019-01-27T04:25:32.942927+00:00 | 239 | false | ```\nclass Solution {\n public String strWithout3a3b(int a, int b) {\n // if a > b, swap a and b\n if (b > a) \n\t\t\treturn helper(a, b);\n \n StringBuilder sb = new StringBuilder();\n // build string like "abababab...."\n while (a > 0 && b > 0) {\n sb.append("a... | 3 | 2 | [] | 2 |
string-without-aaa-or-bbb | Python short and readable solution (beats 99%) | python-short-and-readable-solution-beats-4iy4 | Approach\nAdd \'a\' or \'b\' to the solution one character at a time. Favor the character with higher remaining frequency (being careful not to add three equal | mcervera | NORMAL | 2024-03-14T00:36:08.162047+00:00 | 2024-03-14T00:36:08.162076+00:00 | 311 | false | # Approach\nAdd _\'a\'_ or _\'b\'_ to the solution one character at a time. Favor the character with higher remaining frequency (being careful not to add three equal characters in a row).\n\n# Complexity\n- Time complexity: $$O(a + b)$$\n\n- Space complexity: $$O(1)$$ aside from the output itself\n\n# Code\n```\nclass ... | 2 | 0 | ['Python3'] | 0 |
string-without-aaa-or-bbb | 0MS Beats 100% 👍👍Beginner Friendly Recursive Easy to understand | 0ms-beats-100-beginner-friendly-recursiv-y9hn | Intuition\nPlease Upvote if this Find HelpFull\uD83D\uDC4D\uD83D\uDC4D\n\n# Code\n\nclass Solution {\npublic:\n\n void generator(string &arr,int &a,int &b){\ | anmoldau_50 | NORMAL | 2023-04-30T20:26:47.446442+00:00 | 2023-08-06T01:21:52.251526+00:00 | 668 | false | # Intuition\nPlease Upvote if this Find HelpFull\uD83D\uDC4D\uD83D\uDC4D\n\n# Code\n```\nclass Solution {\npublic:\n\n void generator(string &arr,int &a,int &b){\n\n if (a<=0 && b<=0){\n return;\n }\n\n if(a>b){\n if(a>=2){\n arr=arr+"aa";\n a-... | 2 | 0 | ['String', 'Greedy', 'Recursion', 'C++'] | 0 |
string-without-aaa-or-bbb | GREEDY APPROACH || 0ms || BEATS 100% TIME | greedy-approach-0ms-beats-100-time-by-ar-mp81 | \n\n# Code\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n if(a == 0 && b == 0) return "";\n if(a == 0)return b == 2?"bb | aryanguptaaa | NORMAL | 2023-03-28T16:47:01.949869+00:00 | 2023-03-28T16:47:01.949907+00:00 | 436 | false | \n\n# Code\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n if(a == 0 && b == 0) return "";\n if(a == 0)return b == 2?"bb":"b";\n if(b == 0)return a == 2?"aa":"a";\n string ans = "";\n if(a >= 2*b || b >= 2*a){\n if(a>b){\n while(b... | 2 | 0 | ['C++'] | 1 |
string-without-aaa-or-bbb | c++ greedy solution ✔ | c-greedy-solution-by-1911uttam-hevj | \nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans="";\n \n // while both \'a\' and \'b\' are available\n | 1911Uttam | NORMAL | 2023-01-06T11:00:05.289907+00:00 | 2023-01-06T11:00:05.289949+00:00 | 454 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans="";\n \n // while both \'a\' and \'b\' are available\n while(a && b){\n if(a>b){ // case 1\n ans+= "aab";\n a-=2;\n b--;\n }\n ... | 2 | 0 | ['Greedy', 'C'] | 0 |
string-without-aaa-or-bbb | Python3 🐍 concise solution beats 99% | python3-concise-solution-beats-99-by-avs-i1hj | Code\n\nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n res = []\n while a + b > 0:\n if len(res) >= 2 and res[ | avs-abhishek123 | NORMAL | 2022-12-29T02:01:12.267219+00:00 | 2022-12-29T02:01:12.267255+00:00 | 783 | false | # Code\n```\nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n res = []\n while a + b > 0:\n if len(res) >= 2 and res[-2:] == [\'a\', \'a\']:\n res.append(\'b\')\n b-=1\n elif len(res) >= 2 and res[-2:] == [\'b\', \'b\']:\n ... | 2 | 0 | ['Python3'] | 0 |
string-without-aaa-or-bbb | c++ | easy | short | c-easy-short-by-venomhighs7-jemr | \n\n# Code\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans;\n int ca=0,cb=0;\n while(a>0 || b>0) {\n | venomhighs7 | NORMAL | 2022-11-13T05:31:55.625571+00:00 | 2022-11-13T05:31:55.625608+00:00 | 1,176 | false | \n\n# Code\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans;\n int ca=0,cb=0;\n while(a>0 || b>0) {\n if(a>b) {\n if(ca==2) {\n b--;\n cb=1;\n ca=0;\n ans+="b... | 2 | 0 | ['C++'] | 0 |
string-without-aaa-or-bbb | Easy C++ 100% Faster | easy-c-100-faster-by-absolute-mess-14cu | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans;\n int ca=0,cb=0;\n while(a>0 || b>0) {\n | absolute-mess | NORMAL | 2022-10-10T10:25:33.748227+00:00 | 2022-10-10T10:25:33.748248+00:00 | 603 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans;\n int ca=0,cb=0;\n while(a>0 || b>0) {\n if(a>b) {\n if(ca==2) {\n b--;\n cb=1;\n ca=0;\n ans+="b";\n ... | 2 | 0 | ['C'] | 0 |
string-without-aaa-or-bbb | [Java] Simple recursion | java-simple-recursion-by-mo39-fmbh-ouz3 | Intuition:\n\n- Obviously if a==b just append the mix ab until count gets zero. \n- Then if not equal, let\'s make it equal. So just use one more character of w | mo39-fmbh | NORMAL | 2022-01-05T00:58:35.342671+00:00 | 2022-01-05T01:00:26.460723+00:00 | 139 | false | Intuition:\n\n- Obviously if `a==b` just append the mix `ab` until count gets zero. \n- Then if not equal, let\'s make it equal. So just use one more character of whichever has a larger count.\n\n```\nclass Solution {\n public String strWithout3a3b(int a, int b) {\n if (a == 0 && b == 0) return "";\n i... | 2 | 0 | [] | 1 |
string-without-aaa-or-bbb | Human Readable Explanations - No code | human-readable-explanations-no-code-by-l-r6o9 | The goal is to make a b the same, so we can just apend ababab... to the end of result.\n\n\n(1) if a > b: res += "aab"\n(2) else if b > a: res += "bba"\n(3) els | lilydenris | NORMAL | 2021-08-07T19:21:26.303593+00:00 | 2021-08-07T19:21:26.303631+00:00 | 95 | false | The goal is to make a b the same, so we can just apend ababab... to the end of result.\n\n```\n(1) if a > b: res += "aab"\n(2) else if b > a: res += "bba"\n(3) else : res += "ab" * a\n```\n\nYou might have doubts: what if we have (1) then immediately (2), so we get ```aabbba``` wrong results? \n***No, it is not possbil... | 2 | 1 | [] | 0 |
string-without-aaa-or-bbb | Python 99% - Greedy Approach with comments | python-99-greedy-approach-with-comments-b6153 | \n# M1 - longer\nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n \n # INIT empty string\n res = ""\n availab | daryllman | NORMAL | 2021-06-24T15:41:32.133307+00:00 | 2021-06-24T15:51:01.794446+00:00 | 469 | false | ```\n# M1 - longer\nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n \n # INIT empty string\n res = ""\n available = {\'a\': a, \'b\': b}\n \n # While there are still letters to add\n while a > 0 or b > 0:\n \n currLetter = ""... | 2 | 0 | ['Greedy', 'Python', 'Python3'] | 0 |
string-without-aaa-or-bbb | C++ simple greedy beats 100% | c-simple-greedy-beats-100-by-spyole97-x2h9 | cases:\n1. a == b: in that case "ababababa" or "babababa" will work depending upon the last character of our string.\n2. a > b or b > a: We have to use up the | spyole97 | NORMAL | 2021-05-12T02:13:07.791033+00:00 | 2021-05-12T02:14:13.143497+00:00 | 125 | false | **cases:**\n1. **a == b**: in that case "ababababa" or "babababa" will work depending upon the last character of our string.\n2. **a > b or b > a**: We have to use up the larger one a bit fast so that they are not left behind without a break like after few steps if a >= 3 and b = 0 then we can not stop "aaa" from happ... | 2 | 0 | [] | 0 |
string-without-aaa-or-bbb | Python, 100% faster | python-100-faster-by-llallo-4dey | \nOkay, the concept is so:\n- we are trying to construct the string with "ababab...abbabbabb..." (assuming that giveb count of "a" is smaller that given count o | llallo | NORMAL | 2021-01-23T04:08:08.892672+00:00 | 2021-02-19T12:21:36.279545+00:00 | 193 | false | \nOkay, the concept is so:\n- we are trying to construct the string with "ababab...abbabbabb..." (assuming that giveb count of "a" is smaller that given count of "b", if not just excahnge them)\n- to do so, we ... | 2 | 0 | [] | 1 |
string-without-aaa-or-bbb | [Python], simple, beats 98% | python-simple-beats-98-by-manasswami-nmap | \nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n | manasswami | NORMAL | 2020-05-20T17:05:06.642247+00:00 | 2020-05-20T17:05:06.642335+00:00 | 148 | false | ```\nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n res = ""\n curr = \'a\' if A>B else \'b\'\n while A>0 or B>0:\n if curr == \'a\':\n if A>B and A>1:\n ... | 2 | 0 | [] | 0 |
string-without-aaa-or-bbb | python not fastest but easy to read (36 ms, faster than 73.13%) | python-not-fastest-but-easy-to-read-36-m-6rny | \nclass Solution:\n def strWithout3a3b(self, A: int, B: int) -> str:\n output = ""\n a = 0 # length of last sequence of \'a\'\n b = 0 | talistern21 | NORMAL | 2019-04-25T04:46:41.990624+00:00 | 2019-04-25T04:46:41.990654+00:00 | 300 | false | ```\nclass Solution:\n def strWithout3a3b(self, A: int, B: int) -> str:\n output = ""\n a = 0 # length of last sequence of \'a\'\n b = 0 # length of last sequence of \'b\'\n i = 0\n size = A + B\n \n while i < size:\n if (a < 2 and A > B) or b==2:\n ... | 2 | 0 | ['Python'] | 0 |
string-without-aaa-or-bbb | Python (with explanation) | python-with-explanation-by-frankthecodem-smpd | \nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n | frankthecodemonkey | NORMAL | 2019-02-21T02:43:36.991862+00:00 | 2019-02-21T02:43:36.991905+00:00 | 328 | false | ```\nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n # greedy strategy\n # differ by 2 - take (2,1)\n # differ by 1 - still take(2,1)\n # same - take 1 of each\n \n # we\'l... | 2 | 0 | [] | 0 |
string-without-aaa-or-bbb | Easy to understand java solution | easy-to-understand-java-solution-by-zzz-ilmg | \npublic String strWithout3a3b(int A, int B) {\n if (A > B) {\n return helper(A, \'a\', B, \'b\');\n }\n return helper(B, \'b\', | zzz_ | NORMAL | 2019-02-20T00:20:39.396114+00:00 | 2019-02-20T00:20:39.396179+00:00 | 230 | false | ```\npublic String strWithout3a3b(int A, int B) {\n if (A > B) {\n return helper(A, \'a\', B, \'b\');\n }\n return helper(B, \'b\', A, \'a\');\n }\n\n private String helper(int ca, char a, int cb, char b) {\n StringBuilder sb = new StringBuilder();\n while (ca-- > 0) ... | 2 | 0 | [] | 1 |
string-without-aaa-or-bbb | Java simple recursive solution 4ms beats 99.80% + explanation | java-simple-recursive-solution-4ms-beats-8wcj | The idea is simple:\n1. find max(A,B), and so define MORE and LESS variables\n2. every step we want to decrease the difference MORE-LESS to avoid the case when | olsh | NORMAL | 2019-01-30T22:15:05.341035+00:00 | 2019-01-30T22:15:05.341084+00:00 | 241 | false | The idea is simple:\n1. find max(A,B), and so define MORE and LESS variables\n2. every step we want to decrease the difference MORE-LESS to avoid the case when in the end of the string we have too much same letters. So at the end of algorithm this difference should bw at most = 2.\n3. each letter can repeat contiguonal... | 2 | 0 | [] | 0 |
string-without-aaa-or-bbb | python solution | python-solution-by-born_2_code-pfq3 | \nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n | born_2_code | NORMAL | 2019-01-29T13:58:38.065823+00:00 | 2019-01-29T13:58:38.065865+00:00 | 138 | false | ```\nclass Solution(object):\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n if A == 0:\n return \'b\' * B\n elif B == 0:\n return \'a\' * A\n elif A == B:\n return \'ab\' + self.strWi... | 2 | 0 | [] | 0 |
string-without-aaa-or-bbb | Python3 short and simple | python3-short-and-simple-by-figonet-3rcw | \nclass Solution:\n def strWithout3a3b(self, A, B):\n ans = [] \n while A and B:\n if A > B:\n ans.append(\'aa | figonet | NORMAL | 2019-01-27T18:48:08.487464+00:00 | 2019-01-27T18:48:08.487527+00:00 | 121 | false | ```\nclass Solution:\n def strWithout3a3b(self, A, B):\n ans = [] \n while A and B:\n if A > B:\n ans.append(\'aab\')\n A, B = A - 2, B - 1\n elif A < B:\n ans.append(\'bba\')\n A, B = A - 1, B - 2\n els... | 2 | 1 | [] | 0 |
string-without-aaa-or-bbb | Python 100% using formula | python-100-using-formula-by-anniefromtai-n25d | Assume there will always be more b than a.\nThen the result string would be like the following form - (bb)(abb)(abb)(abb)...(ab)(ab)(ab).\n\nIn conclusion there | anniefromtaiwan | NORMAL | 2019-01-27T07:18:54.035085+00:00 | 2019-01-27T07:18:54.035157+00:00 | 203 | false | Assume there will always be more `b` than `a`.\nThen the result string would be like the following form - `(bb)(abb)(abb)(abb)...(ab)(ab)(ab)`.\n\nIn conclusion there will be three patterns:\n* `bb` - could only appear in the most front of the result string\n* `abb` - assume there are `x` sets of this string (`x>=0`)\... | 2 | 1 | [] | 0 |
string-without-aaa-or-bbb | Python Solution | python-solution-by-here0007-fzpf | \nclass Solution:\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n\n def | here0007 | NORMAL | 2019-01-27T06:14:35.268500+00:00 | 2019-01-27T06:14:35.268542+00:00 | 114 | false | ```\nclass Solution:\n def strWithout3a3b(self, A, B):\n """\n :type A: int\n :type B: int\n :rtype: str\n """\n\n def rec(A,B):\n if B == 0:\n return a*A\n if A == B:\n return (b+a)*A\n elif A - B >= 2:\n ... | 2 | 1 | [] | 0 |
string-without-aaa-or-bbb | JAVA most straightforward and concise solution with detailed explanation!!! | java-most-straightforward-and-concise-so-he8s | \nclass Solution {\n StringBuilder buffer = new StringBuilder();\n public String strWithout3a3b(int A, int B) {\n \n // swap A and B, so th | computer-man94 | NORMAL | 2019-01-27T04:34:03.811226+00:00 | 2019-01-27T04:34:03.811330+00:00 | 113 | false | ```\nclass Solution {\n StringBuilder buffer = new StringBuilder();\n public String strWithout3a3b(int A, int B) {\n \n // swap A and B, so that A represents the greater number of occurance between A and B, a represents that corresponding letter.\n String a = "a";\n String b = "b";\n ... | 2 | 2 | [] | 0 |
string-without-aaa-or-bbb | Short and concise solution | short-and-concise-solution-by-yz5548-x72n | \nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder sb = new StringBuilder();\n int a = 0, b = 0;\n while( | yz5548 | NORMAL | 2019-01-27T04:24:52.280582+00:00 | 2019-01-27T04:24:52.280645+00:00 | 122 | false | ```\nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder sb = new StringBuilder();\n int a = 0, b = 0;\n while(A>0 || B>0){\n if(b<2 && (B-A>1 || a==2 || A==0)){\n sb.append(\'b\');\n B--;b++;\n a=0;\n ... | 2 | 2 | [] | 0 |
string-without-aaa-or-bbb | 🧩 Greedy String Builder – No "aaa" or "bbb" Allowed! 🚫🔥 | greedy-string-builder-no-aaa-or-bbb-allo-5zzm | IntuitionTo avoid having three consecutive 'a's or 'b's, we need to balance the frequency of both characters carefully.
If one character appears more than the o | aditya7483thakur | NORMAL | 2025-04-10T05:35:13.209366+00:00 | 2025-04-10T05:35:13.209366+00:00 | 8 | false | # Intuition
To avoid having three consecutive 'a's or 'b's, we need to balance the frequency of both characters carefully.
If one character appears more than the other, we can occasionally place two of the more frequent character, followed by one of the other, to prevent violating the "no three consecutive letters" rul... | 1 | 0 | ['Java'] | 0 |
string-without-aaa-or-bbb | Easy Approach and Easy to understand(Beat 100%) 😊😊 | easy-approach-and-easy-to-understandbeat-zfnu | Approach and IntuitionThe problem requires constructing a string containing 'a' and 'b' such that no three consecutive 'a's or 'b's appear. Given two integers a | patelaviral | NORMAL | 2025-04-01T05:09:57.791580+00:00 | 2025-04-01T05:09:57.791580+00:00 | 30 | false | # Approach and Intuition
The problem requires constructing a string containing 'a' and 'b' such that no three consecutive 'a's or 'b's appear. Given two integers a and b, representing the count of 'a's and 'b's respectively, we need to construct the longest valid string.
# Intuition
* If a and b are nearly equal, we c... | 1 | 0 | ['String', 'Greedy', 'Java'] | 0 |
string-without-aaa-or-bbb | String Without AAA or BBB | string-without-aaa-or-bbb-by-ansh1707-rc5v | Code | Ansh1707 | NORMAL | 2025-03-02T23:39:44.488052+00:00 | 2025-03-02T23:39:44.488052+00:00 | 31 | false |
# Code
```python []
class Solution(object):
def strWithout3a3b(self, a, b):
"""
:type a: int
:type b: int
:rtype: str
"""
res = []
while a > 0 or b > 0:
if len(res) >= 2 and res[-1] == res[-2]:
write_a = res[-1] == 'b'
... | 1 | 0 | ['String', 'Greedy', 'Python'] | 0 |
string-without-aaa-or-bbb | Easy IF ELSE | easy-if-else-by-madhiarasan-ofam | IntuitionApproachComplexity
Time complexity:O(N)
Space complexity:O(1)
Code | MADHIARASAN | NORMAL | 2025-01-29T08:41:48.865551+00:00 | 2025-01-29T08:41:48.865551+00:00 | 96 | 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(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 1 | 0 | ['Java'] | 0 |
string-without-aaa-or-bbb | Greedy Soln! || Beats 100% || Most Understandable Code! | greedy-soln-beats-100-most-understandabl-973j | Complexity
Time complexity: O(a+b)
Space complexity: O(1)
Code | MandalNitish | NORMAL | 2025-01-10T16:25:11.556911+00:00 | 2025-01-10T16:27:33.704668+00:00 | 114 | false | # Complexity
- Time complexity: O(a+b)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
class Solution {
public:
string strWithout3a3b(int a, int b) {
int s = a+b;
string ans;
int checkA =... | 1 | 0 | ['Greedy', 'C++'] | 0 |
string-without-aaa-or-bbb | Beats 100% C++ | beats-100-c-by-nougght-0bp6 | Code | nougght | NORMAL | 2025-01-03T15:29:40.258272+00:00 | 2025-01-03T15:33:34.527290+00:00 | 78 | false |

# Code
```cpp []
class Solution {
public:
string strWithout3a3b(int a, int b) {
string s{" "};
int balance = 0;
char ch;
while (a+b>0)
{
if (b>0 &... | 1 | 0 | ['String', 'C++'] | 0 |
string-without-aaa-or-bbb | Greedy Solution | greedy-solution-by-vivek_0104-5j6i | IntuitionApproachComplexity
Time complexity:
O(a+b)
Space complexity:
O(a+b)
Code | Vivek_0104 | NORMAL | 2024-12-23T16:27:03.096700+00:00 | 2024-12-23T16:27:03.096700+00:00 | 76 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
- O(a+b)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
- O(a+b)
<!-- Add your space complexity here, e.g. $$O(... | 1 | 0 | ['C++'] | 0 |
string-without-aaa-or-bbb | Simple iterative Python solution, beats more than 60% | simple-iterative-python-solution-beats-m-6chu | Intuition\n-We need to produce solution with length of a+b\n-We need to favorize the letter that has a greater value\n\n# Approach\n-Iterate while a and b are n | sdjuric00 | NORMAL | 2024-11-11T22:32:46.443937+00:00 | 2024-11-11T22:32:46.443968+00:00 | 99 | false | # Intuition\n-We need to produce solution with length of a+b\n-We need to favorize the letter that has a greater value\n\n# Approach\n-Iterate while a and b are not used, use list to keep track of letters\n-If last two added letters are the same, add the opposite letter\n\n# Complexity\n- Time complexity: O(a+b)\n\n\n-... | 1 | 0 | ['String', 'Python3'] | 1 |
string-without-aaa-or-bbb | 0 ms || Beats 100% users || Java | 0-ms-beats-100-users-java-by-gottamharip-xswe | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires generating a string of length a + b such that there are no three c | gottamharipriya | NORMAL | 2024-07-11T19:50:44.322674+00:00 | 2024-07-11T19:50:44.322722+00:00 | 368 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires generating a string of length a + b such that there are no three consecutive \'a\'s or \'b\'s. This can be achieved by alternating between \'a\' and \'b\' characters while ensuring that at no point there are more than... | 1 | 0 | ['Java'] | 1 |
string-without-aaa-or-bbb | Javascript simple solution | javascript-simple-solution-by-gaponov-ko6o | 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 | gaponov | NORMAL | 2024-03-04T12:04:43.787520+00:00 | 2024-03-04T12:04:43.787541+00:00 | 71 | 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$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $... | 1 | 0 | ['JavaScript'] | 0 |
string-without-aaa-or-bbb | Simple StringBuilder Solution | 100% Beats | simple-stringbuilder-solution-100-beats-8h4al | Intuition\n Describe your first thoughts on how to solve this problem. We want to construct a string with \'a\'s and \'b\'s such that there are no consecutive o | Juyel | NORMAL | 2024-02-29T11:25:06.876560+00:00 | 2024-02-29T11:25:06.876589+00:00 | 49 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->We want to construct a string with \'a\'s and \'b\'s such that there are no consecutive occurrences of more than three \'a\'s or \'b\'s.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* We use a StringBuilder to con... | 1 | 0 | ['Greedy', 'Java'] | 0 |
string-without-aaa-or-bbb | Easy C++ solution || Beats 100% | easy-c-solution-beats-100-by-bharathgowd-pnr1 | \n\n# Code\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans;\n int n = a + b;\n int i = 0, acount = 0, | bharathgowda29 | NORMAL | 2024-01-02T19:01:45.021368+00:00 | 2024-01-02T19:01:45.021404+00:00 | 552 | false | \n\n# Code\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans;\n int n = a + b;\n int i = 0, acount = 0, bcount = 0;\n while(i < n){\n if(b > a){\n if(bcount < 2 && b > 0){\n ans.push_back(\'b\');\n ... | 1 | 0 | ['String', 'Greedy', 'C++'] | 0 |
string-without-aaa-or-bbb | Beats 100.00% Users||C++ Code||Easy Understandable Solution | beats-10000-usersc-codeeasy-understandab-mvia | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind this approach is to iteratively construct a string by adding chara | rashmantri | NORMAL | 2023-08-04T16:57:30.654802+00:00 | 2023-08-04T16:57:30.654825+00:00 | 49 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this approach is to iteratively construct a string by adding characters \'a\' and \'b\' while ensuring that no three consecutive characters are the same.\n\n# Approach\nThe approach involves using two variables a and ... | 1 | 0 | ['C++'] | 0 |
string-without-aaa-or-bbb | Solution | solution-by-deleted_user-ehli | C++ []\nclass Solution {\npublic:\n void generator(string &arr,int &a,int &b){\n if (a<=0 && b<=0){\n return;\n }\n if(a>b){\ | deleted_user | NORMAL | 2023-05-17T12:32:25.045198+00:00 | 2023-05-17T13:41:01.159247+00:00 | 662 | false | ```C++ []\nclass Solution {\npublic:\n void generator(string &arr,int &a,int &b){\n if (a<=0 && b<=0){\n return;\n }\n if(a>b){\n if(a>=2){\n arr=arr+"aa";\n a-=2;\n }\n else{\n arr=arr+\'a\';\n ... | 1 | 0 | ['C++', 'Java', 'Python3'] | 0 |
string-without-aaa-or-bbb | ✔️ Clean and well structured C++ implementation (Top 83.1%) || Easy to understand | clean-and-well-structured-c-implementati-94w8 | This Github repository have solution to every problem I looked for https://github.com/AnasImloul/Leetcode-solutions\nIt is very helpful, check it out.\n\n\nclas | UpperNoot | NORMAL | 2023-03-12T01:26:00.413261+00:00 | 2023-03-12T01:26:00.413293+00:00 | 21 | false | This Github repository have solution to every problem I looked for https://github.com/AnasImloul/Leetcode-solutions\nIt is very helpful, check it out.\n\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans="";\n while(a and b){\n if(a > b) ans += "aab", a--;\n... | 1 | 0 | ['C++'] | 0 |
string-without-aaa-or-bbb | by making count of a and b equal and then removing the higher count character beats 100% | by-making-count-of-a-and-b-equal-and-the-ju9s | \n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n int ca =0;\n int cb = 0;\n int times = max(a,b);\n \n | rajsiddi | NORMAL | 2023-03-10T11:35:32.257393+00:00 | 2023-03-10T12:13:24.129801+00:00 | 564 | false | \n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n int ca =0;\n int cb = 0;\n int times = max(a,b);\n \n string ans="";\n\n \n\n if(a>b){\n for(int i=0;i<times;i++){\n ans+="ab";\n }\n int bs = abs(b-a);\n ... | 1 | 0 | ['C++'] | 0 |
string-without-aaa-or-bbb | Runtime 0ms Beats 100% ✅ || Very easy✅ || Solution C++ | runtime-0ms-beats-100-very-easy-solution-v78c | \n\n# Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n | Pushkar2111 | NORMAL | 2023-01-04T19:07:50.568068+00:00 | 2023-01-04T19:07:50.568102+00:00 | 59 | false | \n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans="";\n while(a and b){\n ... | 1 | 0 | ['Greedy', 'C++'] | 0 |
string-without-aaa-or-bbb | 1ms java easy | 1ms-java-easy-by-soqi2001-0sft | ``` \npublic String strWithout3a3b(int a, int b) {\n\t\t//\u53BB\u6389\u591A\u4F59\n StringBuilder sb = new StringBuilder();\n while(a > 0 && b > | soqi2001 | NORMAL | 2022-11-14T11:13:17.702547+00:00 | 2022-11-14T11:13:17.702583+00:00 | 118 | false | ``` \npublic String strWithout3a3b(int a, int b) {\n\t\t//\u53BB\u6389\u591A\u4F59\n StringBuilder sb = new StringBuilder();\n while(a > 0 && b > 0){\n if(a > b){\n a -= 2;\n b--;\n sb.append("aab");\n }else if(a == b){\n a-... | 1 | 0 | ['String', 'Java'] | 0 |
string-without-aaa-or-bbb | 3MS EASY TO UNDERSTAND RECURSION SOLUTION | 3ms-easy-to-understand-recursion-solutio-pcsg | \t\n\tclass Solution {\npublic:\n string ans = "";\n void solve(int a,int b){\n if(a<0 || b<0 || (a==0 && b==0))return ;\n if(a-b>=2){\n | abhay_12345 | NORMAL | 2022-11-11T16:22:22.823561+00:00 | 2022-11-11T16:22:22.823605+00:00 | 819 | false | \t```\n\tclass Solution {\npublic:\n string ans = "";\n void solve(int a,int b){\n if(a<0 || b<0 || (a==0 && b==0))return ;\n if(a-b>=2){\n if(b>0){\n ans = ans + "aab";\n solve(a-2,b-1);}else{\n ans = ans + "aa";\n solve(a-2,b);\n ... | 1 | 1 | ['Greedy', 'Recursion', 'C', 'C++'] | 0 |
string-without-aaa-or-bbb | just check last two chars and append the different one to break the trio | just-check-last-two-chars-and-append-the-qykd | \nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n \n string res = "";\n while(a>0 or b>0)\n {\n if | mr_stark | NORMAL | 2022-08-22T18:56:26.956339+00:00 | 2022-08-22T18:56:26.956377+00:00 | 21 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n \n string res = "";\n while(a>0 or b>0)\n {\n if(b>0 && res.size()>=2 && res[res.size()-1] !=\'b\' && res[res.size()-2] !=\'b\')\n {\n res+=\'b\';\n b--;\n ... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | Python || Greedy || O(N)->TC || O(N)->SC(for returning result) | python-greedy-on-tc-on-scfor-returning-r-aox6 | Simple algo:\n1. add \'a\' to res if a>b else add \'b\'\n2. if we had used \'aa\' then add \'b\' and vice versa\n\'\'\'\n\n\t\tclass Solution:\n\t\tdef strWitho | ak_guy | NORMAL | 2022-07-28T10:32:04.583531+00:00 | 2022-07-28T10:32:39.324920+00:00 | 112 | false | Simple algo:\n1. add \'a\' to res if a>b else add \'b\'\n2. if we had used \'aa\' then add \'b\' and vice versa\n\'\'\'\n\n\t\tclass Solution:\n\t\tdef strWithout3a3b(self, a: int, b: int) -> str:\n\t\t\tres = ""\n\n\t\t\twhile a > 0 or b > 0:\n\t\t\t\tif len(res) > 1 and res[-1] == res[-2] == \'a\':\n\t\t\t\t\tres += ... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | Simple and Elegant C++ Solution with Explanation | simple-and-elegant-c-solution-with-expla-95ur | Consider the Below Example:\n\n\nWe now know that we gotta start with the character with the higher frequency.\n\n\nWhat did we understand from the last example | imanshul | NORMAL | 2022-07-08T17:56:35.396306+00:00 | 2022-07-08T22:15:31.589927+00:00 | 268 | false | **Consider the Below Example:**\n\n\n**We now know that we gotta start with the character with the higher frequency.**\n\n | go-solution-using-stringsbuilder-0ms-by-n5ccc | \nfunc strWithout3a3b(a int, b int) string {\n\tvar sb strings.Builder\n\tsb.Grow(a + b)\n\n\tfor a > 0 || b > 0 {\n\t\tswitch {\n\t\tcase a == 0:\n\t\t\tsb.Wri | superpolikow | NORMAL | 2022-07-06T22:42:39.427602+00:00 | 2022-07-06T22:42:39.427640+00:00 | 38 | false | ```\nfunc strWithout3a3b(a int, b int) string {\n\tvar sb strings.Builder\n\tsb.Grow(a + b)\n\n\tfor a > 0 || b > 0 {\n\t\tswitch {\n\t\tcase a == 0:\n\t\t\tsb.WriteByte(\'b\')\n\t\t\tb--\n\n\t\tcase b == 0:\n\t\t\tsb.WriteByte(\'a\')\n\t\t\ta--\n\n\t\tcase a > b:\n\t\t\tsb.WriteByte(\'a\')\n\t\t\ta--\n\t\t\tsb.WriteBy... | 1 | 0 | ['Go'] | 0 |
string-without-aaa-or-bbb | C++ solution. || Sort of greedy approach. | c-solution-sort-of-greedy-approach-by-sa-bmoy | You may wanna check out 1054. Distant barcodes.\n\n\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans = "";\n int | samarthya2912 | NORMAL | 2022-03-22T13:42:28.554102+00:00 | 2022-03-22T13:43:35.302219+00:00 | 51 | false | You may wanna check out ***1054. Distant barcodes.***\n\n```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n string ans = "";\n int a_streak = 0, b_streak = 0;\n while(a or b) {\n if(b == 0 or b_streak == 2 or (a > b and a_streak < 2)) {\n ans += \'... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | c++ greedy | c-greedy-by-vicky_therock9-0qwv | \nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n int ca=0,cb=0;\n string ans="";\n while(a>0||b>0){\n if | vicky_therock9 | NORMAL | 2022-03-02T05:18:46.942087+00:00 | 2022-03-02T05:18:46.942135+00:00 | 127 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n int ca=0,cb=0;\n string ans="";\n while(a>0||b>0){\n if(a>=b&&ca!=2||cb==2){\n ans+=\'a\';\n ca++;\n a--;\n cb=0;\n }\n else if(b>... | 1 | 0 | ['Greedy', 'C'] | 0 |
string-without-aaa-or-bbb | JavaScript Solution - Greedy Approach | javascript-solution-greedy-approach-by-d-r6pa | The way I solved this problem was thinking about which letter we want to prioritize at each point. If the last two consecutive letters were a mixture of "ab" or | Deadication | NORMAL | 2022-02-06T20:22:55.799721+00:00 | 2022-02-06T20:25:44.630253+00:00 | 154 | false | The way I solved this problem was thinking about which letter we want to prioritize at each point. If the last two consecutive letters were a mixture of "ab" or "ba", then we want to use up the letter we have more. However, if the last two letters were "aa", then we would need to use "b" here because of the constraint ... | 1 | 0 | ['Greedy', 'JavaScript'] | 0 |
string-without-aaa-or-bbb | Python beats 91% | python-beats-91-by-leopardcoderd-ee6m | \nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n res = []\n while a + b > 0:\n if len(res) >= 2 and res[-2:] = | leopardcoderd | NORMAL | 2022-01-30T00:53:36.516376+00:00 | 2022-01-30T00:53:36.516417+00:00 | 291 | false | ```\nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n res = []\n while a + b > 0:\n if len(res) >= 2 and res[-2:] == [\'a\', \'a\']:\n res.append(\'b\')\n b-=1\n elif len(res) >= 2 and res[-2:] == [\'b\', \'b\']:\n r... | 1 | 0 | ['Python', 'Python3'] | 2 |
string-without-aaa-or-bbb | Super simple java solution - straightforward | super-simple-java-solution-straightforwa-jfe3 | \nclass Solution {\n \n public String strWithout3a3b(int a, int b) {\n StringBuilder str = new StringBuilder();\n int size = a + b;\n | rakshaa | NORMAL | 2022-01-01T02:05:05.454985+00:00 | 2022-01-01T02:05:05.455016+00:00 | 80 | false | ```\nclass Solution {\n \n public String strWithout3a3b(int a, int b) {\n StringBuilder str = new StringBuilder();\n int size = a + b;\n int A =0, B = 0;\n \n for(int i =0;i<size;i++) {\n if(a >=b && A != 2 || a > 0 && B==2) {\n str.append(\'a\');\n ... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | C++|| Greedy || Beats 100% | c-greedy-beats-100-by-gnitish31-nf59 | \nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n int m;\n m=max(a,b);\n string s="";\n if(m==a){\n | gnitish31 | NORMAL | 2021-11-01T10:25:36.410201+00:00 | 2021-11-01T10:26:02.119388+00:00 | 68 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n int m;\n m=max(a,b);\n string s="";\n if(m==a){\n while(a && b && a>b){\n if(a>1){\n s+="aa";\n a--;\n }\n else{\n ... | 1 | 0 | ['String', 'Greedy'] | 0 |
string-without-aaa-or-bbb | C++ Simple || 100 % Faster || Greedy || With Comments | c-simple-100-faster-greedy-with-comments-u0me | There can be 3 sitautions a>b, b>a and a=b;\nas we need to avoid three a and b so we greedly doing the following:-\nif(a>b) res.append("aab")\nif(b>a) res.appen | shantys | NORMAL | 2021-08-20T11:50:17.307993+00:00 | 2021-08-20T11:50:17.308034+00:00 | 137 | false | There can be 3 sitautions a>b, b>a and a=b;\nas we need to avoid three a and b so we greedly doing the following:-\nif(a>b) res.append("aab")\nif(b>a) res.append("bba")\nelse res.append("ab")\n\nyou might be thinking what if we will be using more numbers of a and b. there is a trick at the end we will be taking substri... | 1 | 0 | [] | 1 |
string-without-aaa-or-bbb | Java solution for this one and 1405 | java-solution-for-this-one-and-1405-by-a-wkfb | \n\tclass Solution {\n public String strWithout3a3b(int a, int b) {\n return longestDiverseString(a, b, 0);\n }\n \n public String longestDiv | anduchencang | NORMAL | 2021-08-05T23:34:36.068727+00:00 | 2021-08-05T23:35:07.145912+00:00 | 89 | false | ```\n\tclass Solution {\n public String strWithout3a3b(int a, int b) {\n return longestDiverseString(a, b, 0);\n }\n \n public String longestDiverseString(int a, int b, int c) {\n PriorityQueue<Pair> pq = new PriorityQueue<>(\n (x, y) -> Integer.compare(y.freq, x.freq)\n );\n... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | c++ recursion 100% | c-recursion-100-by-theeason123-atab | \nclass Solution {\npublic:\n string strWithout3a3b(int a, int b, string rtnstr = "") {\n \n int totalcount = a + b;\n int counta = 2;\n | Theeason123 | NORMAL | 2021-06-22T08:21:20.493201+00:00 | 2021-06-22T08:21:20.493277+00:00 | 50 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b, string rtnstr = "") {\n \n int totalcount = a + b;\n int counta = 2;\n int countb = 2;\n \n if(totalcount == 0){\n return rtnstr;\n }\n \n if(rtnstr.size()>1){\n ... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | java simple idea 100% | java-simple-idea-100-by-rohanraon-sslw | ```\nclass Solution {\n public String strWithout3a3b(int a, int b) {\n \n// (a,b)->(2,3) ababb (10,2) ababaaaa invalid test case (if(abs(a-b)>3) t | rohanraon | NORMAL | 2021-06-17T10:16:58.389216+00:00 | 2021-06-17T10:17:42.936151+00:00 | 80 | false | ```\nclass Solution {\n public String strWithout3a3b(int a, int b) {\n \n// (a,b)->(2,3) ababb (10,2) ababaaaa invalid test case (if(abs(a-b)>3) then invalid)\n// a>b aabaabaab\n// b>a bbabba..\n// a=b abababab\n \n StringBuilder sb=new StringBuilder("");\n// if it is a valid case when b==0 ... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | 0ms Java Solution | Greedy | 0ms-java-solution-greedy-by-raj02-rd68 | \nclass Solution {\n public String strWithout3a3b(int a, int b) {\n int a_count = 0;\n int b_count = 0;\n int n = a + b;\n \n | raj02 | NORMAL | 2021-06-16T07:04:53.539295+00:00 | 2021-06-16T07:04:53.539339+00:00 | 196 | false | ```\nclass Solution {\n public String strWithout3a3b(int a, int b) {\n int a_count = 0;\n int b_count = 0;\n int n = a + b;\n \n StringBuilder sb = new StringBuilder();\n for(int i = 0; i < n; i++)\n {\n if(a >= b && a_count < 2 || b_count == 2 && a > 0 ){\... | 1 | 0 | ['Greedy', 'Java'] | 0 |
string-without-aaa-or-bbb | C++ | Priority Queue | 0ms | 100% | c-priority-queue-0ms-100-by-hg3994-liz9 | \nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n priority_queue<pair<int, char>> pq;\n if(a) pq.push({a,\'a\'});\n | hg3994 | NORMAL | 2021-06-15T10:51:04.173080+00:00 | 2021-06-15T10:51:04.173119+00:00 | 223 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n priority_queue<pair<int, char>> pq;\n if(a) pq.push({a,\'a\'});\n if(b) pq.push({b,\'b\'});\n string ans = "";\n while(pq.size()>1){\n pair<int, char> one = pq.top(); pq.pop();\n pair<int... | 1 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
string-without-aaa-or-bbb | Easy Python Solution | easy-python-solution-by-dhwanilshah2403-ofk7 | \n\t\tans = \'\'\n while a > 0 or b > 0:\n if a > b and a > 1 and b > 0:\n ans += \'aab\'\n a -= 2\n | dhwanilshah2403 | NORMAL | 2021-05-02T05:02:54.081572+00:00 | 2021-05-02T05:02:54.081601+00:00 | 66 | false | ```\n\t\tans = \'\'\n while a > 0 or b > 0:\n if a > b and a > 1 and b > 0:\n ans += \'aab\'\n a -= 2\n b -= 1\n if a < b and b > 1 and a > 0:\n ans += \'bba\'\n b -= 2\n a -= 1\n if a == b ... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | Java very simple greedy solution beats 100% | java-very-simple-greedy-solution-beats-1-wg7z | Simple idea is that if we have a >= 2*b or b >= 2*a then we consume greedily 2 chars from the character that has more characters followed by the other char. Con | techguy | NORMAL | 2021-04-05T18:18:21.412595+00:00 | 2021-04-05T18:18:21.412623+00:00 | 69 | false | Simple idea is that if we have `a >= 2*b` or `b >= 2*a` then we consume greedily 2 chars from the character that has more characters followed by the other char. Continue doing this repeatedely. Doing so we ensure that the last appended character is the char with lesser count. Now if we have `a >b` then append `ab`, els... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | java Solution || 100% faster | java-solution-100-faster-by-abhishekjain-zryd | \nclass Solution {\n public String strWithout3a3b(int a, int b) {\n StringBuilder s= new StringBuilder();\n if(a==0 && b==0)\n {\n | abhishekjain581 | NORMAL | 2021-03-18T16:57:45.248829+00:00 | 2021-03-18T16:59:07.292440+00:00 | 230 | false | ```\nclass Solution {\n public String strWithout3a3b(int a, int b) {\n StringBuilder s= new StringBuilder();\n if(a==0 && b==0)\n {\n return "";\n }\n\n else{\n \n if(a>b)\n {\n while(a>0)\n {\n ... | 1 | 0 | ['Java'] | 0 |
string-without-aaa-or-bbb | Recursive C++ | Beats 100% | recursive-c-beats-100-by-tanyarajhans7-g0c9 | \nclass Solution {\npublic:\n string s="";\n string strWithout3a3b(int a, int b) {\n if(a==0)\n return string(b,\'b\');\n else if | tanyarajhans7 | NORMAL | 2021-02-03T19:12:38.070143+00:00 | 2021-02-03T19:12:38.070192+00:00 | 85 | false | ```\nclass Solution {\npublic:\n string s="";\n string strWithout3a3b(int a, int b) {\n if(a==0)\n return string(b,\'b\');\n else if(b==0)\n return string(a,\'a\');\n else if(a>b)\n return "aab"+strWithout3a3b(a-2, b-1);\n else if(b>a)\n retu... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | [Python3] greedy O(N) | python3-greedy-on-by-ye15-5iho | Algo\nHere, the strategy is that we choose b whenever we can. Now the question is when it is impossible to put b. There are 2 cases \n1) I just put 2 bs in plac | ye15 | NORMAL | 2020-12-24T04:01:03.451865+00:00 | 2020-12-24T04:01:03.451894+00:00 | 117 | false | **Algo**\nHere, the strategy is that we choose `b` whenever we can. Now the question is when it is impossible to put `b`. There are 2 cases \n1) I just put 2 `b`s in place;\n2) there ain\'t enough `b` left to guarentee no `aaa` (here, the condition to avoid this situation is `2*b < a`). \n\n**Implementation**\n```\ncla... | 1 | 0 | ['Python3'] | 0 |
string-without-aaa-or-bbb | Python solution with simple calculations | python-solution-with-simple-calculations-vawr | \nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n res=[]\n d=a-b\n if d>0:\n g=min(d,b)\n res | umadevi_r | NORMAL | 2020-12-06T18:50:57.109072+00:00 | 2020-12-06T18:50:57.109119+00:00 | 86 | false | ```\nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n res=[]\n d=a-b\n if d>0:\n g=min(d,b)\n res=["aab"]*g\n a-=2*g\n b-=g\n elif d<0:\n g=min(-d,a)\n res=["bba"]*g\n b-=2*g\n a-=g... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | Easy [C++] Greedy Solution 0ms | easy-c-greedy-solution-0ms-by-jintaejin-zc1p | \nclass Solution {\npublic:\n string strWithout3a3b(int A, int B) {\n string ans = "";\n while(A>0 or B>0)\n {\n int n = ans. | jinTaeJin | NORMAL | 2020-11-26T07:55:43.807388+00:00 | 2020-11-26T07:57:24.986539+00:00 | 102 | false | ```\nclass Solution {\npublic:\n string strWithout3a3b(int A, int B) {\n string ans = "";\n while(A>0 or B>0)\n {\n int n = ans.size();\n if(n>1 and ans[n-1]==\'a\' and ans[n-2]==\'a\')\n ans+=\'b\', B--;\n\n else if(n>1 and ans[n-1]==\'b\' and ans... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | Python 99% Faster | python-99-faster-by-wpriddy50-nd8u | class Solution:\n def strWithout3a3b(self, A: int, B: int) -> str:\n a = list(A * \'a\')\n b = list(B * \'b\')\n ans = []\n while | wpriddy50 | NORMAL | 2020-09-08T06:01:47.092007+00:00 | 2020-09-08T06:01:47.092071+00:00 | 91 | false | class Solution:\n def strWithout3a3b(self, A: int, B: int) -> str:\n a = list(A * \'a\')\n b = list(B * \'b\')\n ans = []\n while True:\n try: \n ans.append(a.pop())\n ans.append(b.pop())\n except:\n break\n return ... | 1 | 0 | [] | 2 |
string-without-aaa-or-bbb | Java Solution 100% Runtime 73% Space | java-solution-100-runtime-73-space-by-di-nzmg | \nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder w = new StringBuilder();\n while(A >0 && B >0){\n if(A | dimitriderose | NORMAL | 2020-08-21T04:04:41.091681+00:00 | 2020-08-21T04:04:41.091724+00:00 | 91 | false | ```\nclass Solution {\n public String strWithout3a3b(int A, int B) {\n StringBuilder w = new StringBuilder();\n while(A >0 && B >0){\n if(A==B){\n w.append("a");\n w.append("b");\n A --;\n B --;\n continue;\n }\n if(Math.abs(A-... | 1 | 0 | [] | 1 |
string-without-aaa-or-bbb | Clean Python | One-Liner + O(1) Space Complexity | clean-python-one-liner-o1-space-complexi-0veo | Clean Python | One-Liner + O(1) Space Complexity\n\nThe Python code works based on the following algorithm:\n\n1. If A==B, we output "ab" repeated "A" times. (T | aragorn_ | NORMAL | 2020-08-11T05:38:23.230587+00:00 | 2020-08-11T17:55:32.655066+00:00 | 180 | false | **Clean Python | One-Liner + O(1) Space Complexity**\n\nThe Python code works based on the following algorithm:\n\n1. If A==B, we output "ab" repeated "A" times. (Trivial Answer).\n\n2. If A and B are different, we define the variables "H=max(a,b)" (highest) and "L=min(A,B)" (lowest). For each variable, we store the as... | 1 | 1 | ['Python', 'Python3'] | 0 |
string-without-aaa-or-bbb | very simple C++ code | very-simple-c-code-by-luoyuf-l14r | \nstring strWithout3a3b(int A, int B) {\n\tstring s, res = "";\n\tif (A >= B) s = "ab";\n\telse s = "ba";\n\twhile (A || B) {\n\t\tif (A > B) res += "a", --A;\n | luoyuf | NORMAL | 2020-07-22T04:46:12.619398+00:00 | 2020-07-22T04:46:12.619433+00:00 | 88 | false | ```\nstring strWithout3a3b(int A, int B) {\n\tstring s, res = "";\n\tif (A >= B) s = "ab";\n\telse s = "ba";\n\twhile (A || B) {\n\t\tif (A > B) res += "a", --A;\n\t\telse if (B > A) res += "b", --B;\n\t\tif (A && B) res += s, --A, --B;\n\t}\n\treturn res;\n}\n``` | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | [C++] Simple Solution(100% Time, 98% Memory) | c-simple-solution100-time-98-memory-by-a-msyf | \n\nclass Solution {\npublic:\n \n string strWithout3a3b(int A, int B) {\n \n string finalStr = "";\n while(A || B)\n\t\t{ // Check w | avinsit123 | NORMAL | 2020-07-04T10:24:28.131721+00:00 | 2020-07-04T10:24:28.131764+00:00 | 68 | false | \n```\nclass Solution {\npublic:\n \n string strWithout3a3b(int A, int B) {\n \n string finalStr = "";\n while(A || B)\n\t\t{ // Check whether either A or B is zero \n if(!A) {finalStr += ((B==1) ? "b" : "bb"); break;}\n if(!B) {finalStr += ((A==1) ? "a" : "aa"); break... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | Python String Equations | python-string-equations-by-rushabhh24-3i60 | ```\nstrWithout3a3b(self, A: int, B: int) -> str:\n if A > B:\n if B/A > 0.5:\n return \'aab\' * (A - B) + \'ab\' * (B - (A - B | rushabhh24 | NORMAL | 2020-05-27T16:21:56.170306+00:00 | 2020-05-27T16:26:48.003580+00:00 | 79 | false | ```\nstrWithout3a3b(self, A: int, B: int) -> str:\n if A > B:\n if B/A > 0.5:\n return \'aab\' * (A - B) + \'ab\' * (B - (A - B))\n else:\n return \'aab\' * B + \'a\' * (A - 2 * B)\n else:\n if A/B > 0.5:\n return \'bba\' * (B -... | 1 | 0 | [] | 0 |
string-without-aaa-or-bbb | Python Code [Intuitive] | python-code-intuitive-by-adi10hero-yzc5 | \nclass Solution:\n def solve(self,a,b, A, B):\n # a is the character with count A (may or maynot be \'a\')\n\t\t\t# b is the character with coun | adi10hero | NORMAL | 2020-05-26T08:11:18.455100+00:00 | 2020-05-26T08:11:18.455133+00:00 | 160 | false | ```\nclass Solution:\n def solve(self,a,b, A, B):\n # a is the character with count A (may or maynot be \'a\')\n\t\t\t# b is the character with count B (may or maynot be \'b\')\n\t\t\t# Note : A >= B (check how we\'re calling the function)\n\t\t\tans = []\n idx = 2\n numB = B\n ... | 1 | 0 | ['Greedy', 'Python3'] | 0 |
maximum-erasure-value | An Interesting Optimisation | JAVA Explanation | an-interesting-optimisation-java-explana-vsln | Introduction:\nBefore we discuss the optimisation, let\'s make sure we\'re on the same page regarding the classic two-pointer approach.\nWe can solve this quest | ciote | NORMAL | 2022-06-12T01:13:25.937980+00:00 | 2022-06-12T09:13:43.882248+00:00 | 6,794 | false | ### Introduction:\nBefore we discuss the optimisation, let\'s make sure we\'re on the same page regarding the classic two-pointer approach.\nWe can solve this question by simply expanding a right pointer while keeping track of the sum until we reach a value we\'ve seen before. Then, we increment our left pointer until ... | 112 | 0 | ['Two Pointers', 'Prefix Sum', 'Java'] | 9 |
maximum-erasure-value | Java O(n) - Sliding Window + HashSet | java-on-sliding-window-hashset-by-dev_ps-w5pq | \nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n \n Set<Integer> set = new HashSet();\n \n int sum =0, ans =0 | dev_ps | NORMAL | 2020-12-20T04:10:10.433207+00:00 | 2020-12-20T04:13:29.388810+00:00 | 11,371 | false | ```\nclass Solution {\n public int maximumUniqueSubarray(int[] nums) {\n \n Set<Integer> set = new HashSet();\n \n int sum =0, ans =0;\n int j = 0;\n \n int i = 0;\n \n while(i<nums.length && j<nums.length){\n \n if(!set.contains(num... | 97 | 3 | ['Two Pointers'] | 21 |
maximum-erasure-value | [Python] sliding window solution, explained | python-sliding-window-solution-explained-15gx | In this problem we need to find subarray with biggest sum, which has only unique elements. This is in fact almost the same as problem 3. Longest Substring Witho | dbabichev | NORMAL | 2021-05-28T09:50:42.470538+00:00 | 2021-05-28T12:19:15.168234+00:00 | 4,909 | false | In this problem we need to find subarray with biggest sum, which has only unique elements. This is in fact almost the same as problem **3. Longest Substring Without Repeating Characters**, but here we need to find sum, not length. But idea is exaclty the same:\n\nLet us keep window with elements `[beg: end)`, where fir... | 92 | 13 | ['Two Pointers', 'Sliding Window'] | 6 |
maximum-erasure-value | [Python/Java/C++] Sliding Window & HashMap - Clean & Concise - O(N) | pythonjavac-sliding-window-hashmap-clean-xxxw | Idea\n- This problem is about to find the maximum sum of subarrray (where elements in subarray is unique) in an array.\n- This is a classic Sliding Window probl | hiepit | NORMAL | 2021-05-28T07:16:11.897494+00:00 | 2021-05-28T09:22:05.168985+00:00 | 3,737 | false | **Idea**\n- This problem is about to find the **maximum sum** of subarrray (where elements in subarray is unique) in an array.\n- This is a classic Sliding Window problem which is simillar to this problem [3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeati... | 70 | 29 | [] | 5 |
maximum-erasure-value | ✅ [C++/Python] Simple Solution w/ Explanation | Sliding Window | cpython-simple-solution-w-explanation-sl-vytm | If you are doing Daily LeetCoding Challenge for June, I highly recommend you look at the problem given on June 10: 3. Longest Substring Without Repeating Charac | r0gue_shinobi | NORMAL | 2022-06-12T02:34:51.785194+00:00 | 2022-06-12T03:56:24.547193+00:00 | 6,955 | false | If you are doing Daily LeetCoding Challenge for June, I highly recommend you look at the problem given on June 10: [3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/). I have already briefly discussed that problem [in this post](https://leet... | 66 | 0 | ['Two Pointers', 'Sliding Window', 'Ordered Set', 'Python'] | 7 |
maximum-erasure-value | C++ O(n) sliding window with hash set | c-on-sliding-window-with-hash-set-by-min-xpbp | \nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int result = 0;\n unordered_set<int> hset;\n for (int i = | mingrui | NORMAL | 2020-12-20T04:03:46.115904+00:00 | 2020-12-20T04:03:46.115950+00:00 | 9,191 | false | ```\nclass Solution {\npublic:\n int maximumUniqueSubarray(vector<int>& nums) {\n int result = 0;\n unordered_set<int> hset;\n for (int i = 0, j = 0, win = 0; j < nums.size(); j++) {\n while (hset.find(nums[j]) != hset.end()) {\n hset.erase(nums[i]);\n wi... | 63 | 0 | [] | 10 |
maximum-erasure-value | ✅ Maximum Erasure Value | Easy Solution using 2-Pointers and Hashset w/ Explanation | maximum-erasure-value-easy-solution-usin-vfhh | \u2714\uFE0F Solution (using 2-Pointers and HashSet)\n\nWe need to check every sub-array having unique elements and find the one having the maximum sum. Obvious | archit91 | NORMAL | 2021-05-28T08:01:04.017938+00:00 | 2021-05-28T08:54:36.866701+00:00 | 3,555 | false | \u2714\uFE0F ***Solution (using 2-Pointers and HashSet)***\n\nWe need to check every sub-array having unique elements and find the one having the maximum sum. Obviously, with the given constraints, we can\'t check every sub-array individually.\n\nWe need to realise that we can **choose the first element and keep extend... | 51 | 2 | ['C', 'Python'] | 2 |
maximum-erasure-value | ✅ Easy Solution using 2 Pointers with HashSet w/ Explanation | Beats 100% | easy-solution-using-2-pointers-with-hash-9dj8 | \u2714\uFE0F Solution (using 2-Pointers and HashSet)\n\nWe need to check every sub-array having unique elements and find the one having the maximum sum. Obvious | archit91 | NORMAL | 2021-05-28T07:58:37.597232+00:00 | 2021-05-28T08:56:23.013247+00:00 | 1,840 | false | \u2714\uFE0F ***Solution (using 2-Pointers and HashSet)***\n\nWe need to check every sub-array having unique elements and find the one having the maximum sum. Obviously, with the given constraints, we can\'t check every sub-array individually.\n\nWe need to realise that we can **choose the first element and keep extend... | 26 | 6 | ['C', 'Python'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.