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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
remove-outermost-parentheses | Java♨️ || 2 Approaches(With+Without Stack) ✅ | java-2-approacheswithwithout-stack-by-ri-f5lj | The main thing is --> (()()) --> If the stack(or counter) is greater than 1 then include "(" and ")" in answer else don\'t include as we need to remove outermos | Ritabrata_1080 | NORMAL | 2022-09-21T21:56:28.922615+00:00 | 2022-10-25T09:28:36.289669+00:00 | 1,577 | false | **The main thing is --> (()()) --> If the stack(or counter) is greater than 1 then include "(" and ")" in answer else don\'t include as we need to remove outermost parenthesis... If you find the solution helpful please upvote :)**\n\n**Without stack approach -->**\n```\nclass Solution {\n public String removeOuterP... | 12 | 0 | ['Stack', 'Java'] | 0 |
remove-outermost-parentheses | Java in 6 lines | java-in-6-lines-by-silviodp3-y06z | \nclass Solution {\n public String removeOuterParentheses(String s) {\n \n int count = 0;\n\t\tStringBuilder sb = new StringBuilder();\n\t\t\n\ | silviodp3 | NORMAL | 2019-06-09T03:13:28.330331+00:00 | 2019-06-09T03:13:28.330395+00:00 | 1,801 | false | ```\nclass Solution {\n public String removeOuterParentheses(String s) {\n \n int count = 0;\n\t\tStringBuilder sb = new StringBuilder();\n\t\t\n\t\tfor (char c : s.toCharArray()) {\n\n\t\t\tif (c == \'(\' && count++ > 0) { sb.append(c); }\n\t\t\tif (c == \')\' && --count > 0) { sb.append(c); }\n\t\t\t... | 12 | 0 | [] | 3 |
remove-outermost-parentheses | Simple O(n) Java solution | simple-on-java-solution-by-hobiter-2hdg | Thanks to fengyunzhe90.\n\n```\nclass Solution {\n public String removeOuterParentheses(String s) {\n Stack stack = new Stack<>();\n \n | hobiter | NORMAL | 2019-04-07T05:50:15.890058+00:00 | 2019-04-07T05:50:15.890147+00:00 | 1,354 | false | Thanks to fengyunzhe90.\n\n```\nclass Solution {\n public String removeOuterParentheses(String s) {\n Stack<Character> stack = new Stack<>();\n \n String result = "";\n \n for (int i = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n \n if (stack... | 12 | 0 | [] | 1 |
remove-outermost-parentheses | Easy and Simple Approach ✅ || Beats 100% 🎯 | easy-and-simple-approach-beats-100-by-rc-ju0a | \n# Code\n\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n string ans;\n int cnt = 0;\n for (char chr : s)\n | rckrockerz | NORMAL | 2024-05-23T04:57:46.982511+00:00 | 2024-06-12T15:12:09.654368+00:00 | 1,656 | false | \n# Code\n```\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n string ans;\n int cnt = 0;\n for (char chr : s)\n if (chr == \'(\')\n ... | 11 | 0 | ['String', 'Stack', 'C++'] | 1 |
remove-outermost-parentheses | JAVA }} O(n) || Easy Approach With comment | java-on-easy-approach-with-comment-by-sw-vykt | \nclass Solution\n{\n public String removeOuterParentheses(String S) \n {\n Stack<Character> valid=new Stack<>();//checking the balance and when th | swapnilGhosh | NORMAL | 2021-06-26T08:40:25.533566+00:00 | 2021-06-26T08:41:03.511772+00:00 | 1,486 | false | ```\nclass Solution\n{\n public String removeOuterParentheses(String S) \n {\n Stack<Character> valid=new Stack<>();//checking the balance and when the stack is Empty\n List<Integer> index=new ArrayList<>();//for storing the index\n char ch;\n \n for(int i=0;i<S.length();i++)//t... | 11 | 0 | ['Stack', 'Java'] | 0 |
remove-outermost-parentheses | 0 ms C++ Approach | 0-ms-c-approach-by-akashrajakku-m711 | Intuition\n Describe your first thoughts on how to solve this problem. \nA valid string has equal number of \'(\' and \')\' braces. So if we keep count of numbe | akashrajakku | NORMAL | 2024-01-23T06:00:38.497829+00:00 | 2024-01-23T06:00:38.497855+00:00 | 1,298 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA valid string has equal number of \'(\' and \')\' braces. So if we keep count of number of opening and closing braces, we can check for a valid parenthesis easily.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nW... | 10 | 0 | ['C++'] | 2 |
remove-outermost-parentheses | stack java | stack-java-by-niyazjava-kd56 | If you like it pls upvote\n\n\n public String removeOuterParentheses(String s) {\n Stack<Character> st = new Stack<>();\n StringBuilder sb = ne | NiyazJava | NORMAL | 2022-11-01T09:17:12.855279+00:00 | 2022-11-07T17:31:29.826661+00:00 | 1,821 | false | If you like it pls upvote\n```\n\n public String removeOuterParentheses(String s) {\n Stack<Character> st = new Stack<>();\n StringBuilder sb = new StringBuilder();\n\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == \'(\') {\n if (st.size() >= 1) {\n ... | 10 | 0 | ['Stack', 'Java'] | 2 |
remove-outermost-parentheses | Clean JavaScript Solution | clean-javascript-solution-by-shimphillip-d2c0 | \n// time O(n) space O(n)\nvar removeOuterParentheses = function(S) {\n let result = \'\'\n let level = 0\n \n for(const item of S) {\n if(it | shimphillip | NORMAL | 2020-10-29T21:01:32.824440+00:00 | 2020-11-13T19:08:44.768081+00:00 | 1,097 | false | ```\n// time O(n) space O(n)\nvar removeOuterParentheses = function(S) {\n let result = \'\'\n let level = 0\n \n for(const item of S) {\n if(item === \')\') {\n level--\n }\n if(level >= 1) {\n result += item \n }\n if(item === \'(\') ... | 10 | 0 | ['JavaScript'] | 0 |
remove-outermost-parentheses | C++ solution using stack | c-solution-using-stack-by-sat5683-c270 | ```class Solution {\npublic:\n string removeOuterParentheses(string S) {\n string result="";\n stack st;\n for(auto ch : S){\n | sat5683 | NORMAL | 2019-04-08T18:14:04.352162+00:00 | 2019-04-08T18:14:04.352209+00:00 | 740 | false | ```class Solution {\npublic:\n string removeOuterParentheses(string S) {\n string result="";\n stack<char> st;\n for(auto ch : S){\n if(ch==\'(\'){\n if(st.size()>0){\n result+=ch;\n }\n st.push(ch);\n }\n ... | 10 | 1 | ['Stack'] | 0 |
remove-outermost-parentheses | Easy solution 🚀| Detailed explanation☑️☑️ | Beginner friendly 📍| | easy-solution-detailed-explanation-begin-k7wp | Approach\n1. Initialization:\n\n- Initialize an empty string ans to store the result.\n2. Iterating Over Characters:\n\n- We will Iterate through each character | Prabhakar_s_kulkarni | NORMAL | 2024-02-28T05:55:57.207355+00:00 | 2024-02-28T05:56:39.196543+00:00 | 713 | false | # Approach\n1. Initialization:\n\n- Initialize an empty string ans to store the result.\n2. Iterating Over Characters:\n\n- We will Iterate through each character ch in the input string s.\n3. Tracking Parentheses Count:\n\n- Maintain a variable count to keep track of the current nesting level of parentheses.\n- When e... | 9 | 0 | ['String', 'C++'] | 1 |
remove-outermost-parentheses | C++ 0ms shortest code | c-0ms-shortest-code-by-nikunjdaskasat-dkx3 | \nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n stack<char> st;\n string ans;\n for(char c: S)\n {\n | nikunjdaskasat | NORMAL | 2020-12-19T09:26:51.973833+00:00 | 2020-12-19T09:26:51.973865+00:00 | 613 | false | ```\nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n stack<char> st;\n string ans;\n for(char c: S)\n {\n if(c == \')\') st.pop();\n if(!st.empty()) ans += c;\n if(c == \'(\') st.push(c);\n }\n return ans;\n }\n};\n... | 9 | 1 | ['Stack', 'C'] | 0 |
remove-outermost-parentheses | JavaScript counter solution | javascript-counter-solution-by-kremenher-f0o2 | \n/**\n * @param {string} S\n * @return {string}\n */\nvar removeOuterParentheses = function(S) {\n let counter = 0;\n let result = \'\';\n \n for ( | kremenhero | NORMAL | 2019-04-07T16:24:17.982440+00:00 | 2019-04-07T16:24:17.982484+00:00 | 1,694 | false | ```\n/**\n * @param {string} S\n * @return {string}\n */\nvar removeOuterParentheses = function(S) {\n let counter = 0;\n let result = \'\';\n \n for (let i = 0; i < S.length; i++) {\n if ((S[i] === \'(\' && ++counter !== 1) || (S[i] === \')\' && --counter !== 0)) {\n result += S[i];\n ... | 9 | 1 | ['JavaScript'] | 3 |
remove-outermost-parentheses | Easy C++ Solution || Beginner Friendly ✅✅ | easy-c-solution-beginner-friendly-by-man-5xbw | \n# Approach\nThis question is all about the counter. As the very first bracket would start from 0 and thus that will not be included and the last outermost bra | Manisha_jha658 | NORMAL | 2023-08-10T14:34:55.319187+00:00 | 2023-08-10T14:50:50.387810+00:00 | 1,373 | false | \n# Approach\nThis question is all about the counter. As the very first bracket would start from 0 and thus that will not be included and the last outermost bracket with value 0 will also be not included.\n\nIn this way we will check whether the char should be added into the string or not. \nAdd 1 if there is \'(\' ope... | 8 | 0 | ['C++'] | 5 |
remove-outermost-parentheses | C++✅✅| Beats 100% | self-Explained🔥 | Beginner Friendly Approach✔ | Clean Code |stack | c-beats-100-self-explained-beginner-frie-v9px | 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 | Rhythm_1383 | NORMAL | 2023-08-07T11:04:48.152601+00:00 | 2023-08-07T11:04:48.152620+00:00 | 1,392 | 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)$$ --... | 8 | 0 | ['Stack', 'C++'] | 1 |
remove-outermost-parentheses | C++ and C# very easy solution. | c-and-c-very-easy-solution-by-aloneguy-0cz9 | Intuition:First of all,we have to find outer parentheses and after that we have to add other parentheses to a new string.\n Describe your first thoughts on how | aloneguy | NORMAL | 2023-04-10T00:43:32.355092+00:00 | 2023-04-10T00:43:32.355126+00:00 | 2,602 | false | # Intuition:First of all,we have to find outer parentheses and after that we have to add other parentheses to a new string.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach:Each pair has a couple of parenthese.So we use stack to declare which parenthese is either opener or cleser.\n<!-... | 8 | 0 | ['String', 'Stack', 'C++', 'C#'] | 0 |
remove-outermost-parentheses | ✅ C++ 2 solutions: stack & counter | c-2-solutions-stack-counter-by-yespower-xuk3 | Solution 1 : Use std::stackIntuitionTo solve this problem, we can keep track of the outer parentheses using a stack. Whenever we encounter an open parenthesis, | yespower | NORMAL | 2020-03-02T06:51:49.362046+00:00 | 2025-02-26T20:40:08.065574+00:00 | 905 | false | # Solution 1 : Use std::stack
## Intuition
To solve this problem, we can keep track of the outer parentheses using a stack. Whenever we encounter an open parenthesis, we push it onto the stack. When we encounter a close parenthesis, we pop an open parenthesis from the stack. We only add the current character to our re... | 8 | 0 | ['C', 'C++'] | 0 |
remove-outermost-parentheses | simple and easy Python solution 😍❤️🔥 | simple-and-easy-python-solution-by-shish-k8ml | \n\n\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Face | shishirRsiam | NORMAL | 2024-08-21T03:37:59.168148+00:00 | 2024-08-21T03:37:59.168172+00:00 | 1,266 | false | \n\n\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: www.fb.com/shishirrsiam\n\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-... | 7 | 0 | ['String', 'Stack', 'Python', 'Python3'] | 3 |
remove-outermost-parentheses | ✅C++|| Stack And Without Stack || Easy Solution | c-stack-and-without-stack-easy-solution-dxyj8 | Approach 1: (Stack) \u2705\n\nC++\n\nclass Solution {\npublic:\n\nstring removeOuterParentheses(string S) {\n stack<char>st;\n string ans;\n for(auto a | indresh149 | NORMAL | 2022-10-19T06:58:45.148934+00:00 | 2022-10-19T06:58:45.148972+00:00 | 1,286 | false | **Approach 1: (Stack) \u2705**\n\n**C++**\n```\nclass Solution {\npublic:\n\nstring removeOuterParentheses(string S) {\n stack<char>st;\n string ans;\n for(auto a:S)\n {\n if(a==\'(\')\n {\n if(st.size()>0)\n {\n ans+=\'(\';\n }\n st.p... | 7 | 0 | ['String', 'Stack', 'C'] | 1 |
remove-outermost-parentheses | Remove Outermost Parentheses|| cpp|| easy way | remove-outermost-parentheses-cpp-easy-wa-9vzf | \n\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n int count = 0;\n string ans = "";\n for(int i=0;i0){\n | shraddha1517 | NORMAL | 2022-09-26T16:41:02.248109+00:00 | 2022-09-26T16:41:02.248137+00:00 | 1,388 | false | ```\n```\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n int count = 0;\n string ans = "";\n for(int i=0;i<s.length();i++){\n if( s[i]==\'(\' && count == 0){\n count++;\n }\n else\n if(s[i]==\'(\' && count>0)... | 7 | 0 | [] | 0 |
remove-outermost-parentheses | java two solution 1. using stack 2.simple for loop | java-two-solution-1-using-stack-2simple-db033 | using Stack\n\nclass Solution {\n public String removeOuterParentheses(String S) {\n Stack<Character> st=new Stack();\n StringBuilder sb=new St | va_asu_ | NORMAL | 2021-06-04T04:45:04.082067+00:00 | 2021-06-04T04:45:04.082113+00:00 | 1,028 | false | using Stack\n```\nclass Solution {\n public String removeOuterParentheses(String S) {\n Stack<Character> st=new Stack();\n StringBuilder sb=new StringBuilder();\n for(char ch:S.toCharArray())\n {\n if(ch==\'(\')\n {\n if(st.size()>=1)\n ... | 7 | 0 | ['Stack', 'Java'] | 0 |
remove-outermost-parentheses | Python Simplest Solution | python-simplest-solution-by-aishwaryanat-pfic | \nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n \n stack=[]\n counter=0\n for i in S:\n if i==\ | aishwaryanathanii | NORMAL | 2021-04-17T04:05:40.427888+00:00 | 2021-04-17T04:05:40.427930+00:00 | 653 | false | ```\nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n \n stack=[]\n counter=0\n for i in S:\n if i==\'(\':\n counter=counter+1\n if counter==1:\n pass\n else:\n stack.append(i... | 7 | 0 | ['Python', 'Python3'] | 0 |
remove-outermost-parentheses | Easy and Simple Solution | easy-and-simple-solution-by-mayankluthya-yt1l | Please Like ❤️IntuitionTo remove the outermost parentheses of each valid primitive string in a valid parentheses string, the approach revolves around maintainin | mayankluthyagi | NORMAL | 2025-01-24T16:45:42.542113+00:00 | 2025-01-24T16:45:42.542113+00:00 | 1,056 | false | ```java
class Solution {
public String removeOuterParentheses(String s) {
StringBuilder str = new StringBuilder();
int count = 0;
for (char ch : s.toCharArray()) {
if (ch == '(') {
if (count > 0) str.append("(");
count++;
} else {
... | 6 | 0 | ['Java'] | 0 |
remove-outermost-parentheses | simple and easy Javascript solution 😍❤️🔥 | simple-and-easy-javascript-solution-by-s-1z32 | \n\n\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Face | shishirRsiam | NORMAL | 2024-08-21T03:40:14.206792+00:00 | 2024-08-21T03:40:14.206835+00:00 | 476 | false | \n\n\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: www.fb.com/shishirrsiam\n\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-... | 6 | 0 | ['String', 'Stack', 'JavaScript'] | 3 |
remove-outermost-parentheses | ✔️✔️✔️very easy solution - without STACK - beats 100%⚡⚡⚡PYTHON || C++ | very-easy-solution-without-stack-beats-1-yozf | Code\nPython []\nclass Solution:\n def removeOuterParentheses(self, s: str) -> str:\n string = ""\n opened = 0\n for i in s:\n | anish_sule | NORMAL | 2024-04-22T07:21:23.306497+00:00 | 2024-04-22T07:34:03.898510+00:00 | 897 | false | # Code\n```Python []\nclass Solution:\n def removeOuterParentheses(self, s: str) -> str:\n string = ""\n opened = 0\n for i in s:\n if i == "(":\n opened += 1\n if opened > 1:\n string += i\n else:\n opened -= ... | 6 | 0 | ['String', 'C++', 'Python3'] | 0 |
remove-outermost-parentheses | Remove Outermost Parenthesis || Beats 100% || Java || Fully Explained | remove-outermost-parenthesis-beats-100-j-7hfv | Approach\n- The method starts by initializing a StringBuilder to construct the final result. Declare an int variable cnt to keep track of the number of open par | Vishu6403 | NORMAL | 2023-11-11T17:42:16.888335+00:00 | 2023-11-11T17:42:16.888362+00:00 | 913 | false | # Approach\n- The method starts by initializing a StringBuilder to construct the final result. Declare an int variable `cnt` to keep track of the number of open parentheses encountered.\n- Iterate through each character of string s. Within the loop, the code checks if the current character is an opening parenthesis `\'... | 6 | 0 | ['String', 'Java'] | 0 |
remove-outermost-parentheses | c++ beats 100% ✅ | with explaination | O(n) time, O(1) space | c-beats-100-with-explaination-on-time-o1-bzin | Intuition\nOpening parenthesis decreases the counter and closing parenthesis increases the counter\n\n ( ( ) ( ) ) ( ( ) )\n0 -1 -2 -1 -2 -1 0 -1 -2 -1 | vikas107sharma | NORMAL | 2023-08-09T14:43:36.202660+00:00 | 2023-08-09T14:43:36.202685+00:00 | 417 | false | # Intuition\nOpening parenthesis decreases the counter and closing parenthesis increases the counter\n```\n ( ( ) ( ) ) ( ( ) )\n0 -1 -2 -1 -2 -1 0 -1 -2 -1 0\n```\n\nThere is always a primitive string after a zero till next zero.\nWe just need to remove first and last character of primitive string.\n\nSo the ... | 6 | 0 | ['C++'] | 0 |
remove-outermost-parentheses | Python || 96.77% Faster || Explained || Without Stack || O(n) Solution | python-9677-faster-explained-without-sta-qfyt | \nclass Solution:\n def removeOuterParentheses(self, s: str) -> str:\n c,j,n=0,0,len(s)\n ans=[]\n for i in range(n):\n if s[ | pulkit_uppal | NORMAL | 2022-11-16T06:54:22.396264+00:00 | 2022-12-03T11:04:33.758468+00:00 | 1,647 | false | ```\nclass Solution:\n def removeOuterParentheses(self, s: str) -> str:\n c,j,n=0,0,len(s)\n ans=[]\n for i in range(n):\n if s[i]==\'(\':\n c+=1 #If there is opening paranthesis we increment the counter variable\n else:\n c-=1 #If there is clo... | 6 | 0 | ['Python', 'Python3'] | 1 |
remove-outermost-parentheses | Simple, short and concise | C++ | simple-short-and-concise-c-by-tusharbhar-905c | \nclass Solution {\npublic:\n string removeOuterParentheses(string str) {\n string ans = "";\n stack<char> s;\n \n for(char c : s | TusharBhart | NORMAL | 2022-04-15T13:43:14.827114+00:00 | 2022-04-15T13:43:14.827140+00:00 | 327 | false | ```\nclass Solution {\npublic:\n string removeOuterParentheses(string str) {\n string ans = "";\n stack<char> s;\n \n for(char c : str){\n if(c == \'(\') s.push(c);\n if(s.size() > 1) ans += c;\n if(c == \')\') s.pop();\n }\n \n return... | 6 | 0 | ['Stack', 'C'] | 0 |
remove-outermost-parentheses | 100% fastest solution | Explained every line | Efficient | Easy to understand | cpp | O(n) | 100-fastest-solution-explained-every-lin-03gx | 100% fastest solution | Explained every line | Efficient | Easy to understand | cpp | O(n)\n\nclass Solution {\npublic:\n string removeOuterParentheses(strin | divyanshnigam1612 | NORMAL | 2021-09-26T17:03:36.323918+00:00 | 2021-09-26T17:03:36.323947+00:00 | 795 | false | 100% fastest solution | Explained every line | Efficient | Easy to understand | cpp | O(n)\n```\nclass Solution {\npublic:\n string removeOuterParentheses(string s) \n {\n string ans;\n stack<char> st;\n\n for(auto x: s)\n {\n if(x==\'(\') // 1. ->add to stack 2. -> add... | 6 | 1 | ['Stack', 'C', 'C++'] | 0 |
remove-outermost-parentheses | Python simple solution with explanation | python-simple-solution-with-explanation-col7n | \nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n result = \'\'\n depth = 0\n for index in range(0, len(S) - 1):\n | peatear-anthony | NORMAL | 2021-01-17T04:14:17.169786+00:00 | 2021-01-17T04:24:16.382450+00:00 | 739 | false | ```\nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n result = \'\'\n depth = 0\n for index in range(0, len(S) - 1):\n char = S[index]\n if depth != 0:\n result += char\n if char == "(" and S[index + 1] == "(":\n ... | 6 | 1 | ['Python', 'Python3'] | 0 |
remove-outermost-parentheses | Python solution beats 99% | python-solution-beats-99-by-soloz-cqdn | Traverse the string S from left to right. Time: O(N).\n\nUse the variable net to record the current net number of parenthese -- \'(\' contributes +1 and \')\' c | soloz | NORMAL | 2019-07-19T03:41:44.679704+00:00 | 2019-07-19T03:41:44.679752+00:00 | 531 | false | Traverse the string `S` from left to right. Time: O(N).\n\nUse the variable `net` to record the current net number of parenthese -- \'(\' contributes +1 and \')\' contributes -1. \n\nThe variable \'start\' is to store the starting index of the next primitive part in \'S\'.\n\nWhenever \'net\' becomes 0, one concludes t... | 6 | 0 | [] | 0 |
remove-outermost-parentheses | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-kwmn | \n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook | shishirRsiam | NORMAL | 2024-08-21T03:35:36.834773+00:00 | 2024-08-21T03:35:36.834803+00:00 | 867 | false | \n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: www.fb.com/shishirrsiam\n\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Ad... | 5 | 0 | ['String', 'Stack', 'C++'] | 4 |
remove-outermost-parentheses | ✅ 2 POINTER APPROACH || Beats 100%✅ || C++ || Without Using Stack || BEGINNER FRIENDLY | 2-pointer-approach-beats-100-c-without-u-o78k | Intuition\nGiven the problem of removing the outermost parentheses from every primitive valid parentheses string in a given valid parentheses string s, the main | V15H4L | NORMAL | 2024-06-10T15:46:25.279248+00:00 | 2024-06-10T15:46:25.279278+00:00 | 451 | false | # Intuition\nGiven the problem of removing the outermost parentheses from every primitive valid parentheses string in a given valid parentheses string `s`, the main idea is to identify these primitive segments and remove their outermost parentheses. A two-pointer approach can be effectively used to identify these segme... | 5 | 0 | ['Two Pointers', 'String', 'C++'] | 0 |
remove-outermost-parentheses | easy way 🔥|| without stack | easy-way-without-stack-by-tanmay_jaiswal-eqmd | \nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n int cnt = 0;\n string res;\n\n for (auto c: s) {\n | tanmay_jaiswal_ | NORMAL | 2023-07-11T21:51:51.041348+00:00 | 2023-07-11T21:51:51.041371+00:00 | 1,174 | false | ```\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n int cnt = 0;\n string res;\n\n for (auto c: s) {\n if (cnt == 0 && c == \'(\') cnt--;\n else if (cnt == -1 && c == \')\') cnt++;\n else {\n res.push_back(c);\n ... | 5 | 0 | ['C++'] | 0 |
remove-outermost-parentheses | Best O(N) Solution | best-on-solution-by-kumar21ayush03-f038 | \n\n# Approach\nBest Approach\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n string removeOu | kumar21ayush03 | NORMAL | 2023-01-28T14:33:52.555811+00:00 | 2023-01-28T14:33:52.555861+00:00 | 535 | false | \n\n# Approach\nBest Approach\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n int count = 0;\n string ans = "";\n for (int i = 0; i < s.size(); i++) {\n if (s[i] == \... | 5 | 0 | ['C++'] | 0 |
remove-outermost-parentheses | simple cpp solution using stack | simple-cpp-solution-using-stack-by-prith-k8uq | 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 | prithviraj26 | NORMAL | 2023-01-24T16:50:43.248159+00:00 | 2023-01-24T16:50:43.248215+00:00 | 873 | 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)$$ --... | 5 | 0 | ['String', 'Stack', 'C++'] | 0 |
remove-outermost-parentheses | Java | without using stack | simple one | java-without-using-stack-simple-one-by-v-u7vp | 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 | Venkat089 | NORMAL | 2023-01-17T09:05:53.234559+00:00 | 2023-01-17T09:05:53.234700+00:00 | 1,782 | 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)$$ --... | 5 | 0 | ['Java'] | 0 |
remove-outermost-parentheses | [Java] ✅Faster Solution 99.85% Big O(N) || Without Stack | java-faster-solution-9985-big-on-without-bvma | \n\n# Code\n\nclass Solution {\n public String removeOuterParentheses(String s) {\n int count = 0;\n StringBuilder str = new StringBuilder();\n | deleted_user | NORMAL | 2022-11-21T03:57:10.143050+00:00 | 2022-11-21T03:57:59.332065+00:00 | 1,060 | false | \n\n# Code\n```\nclass Solution {\n public String removeOuterParentheses(String s) {\n int count = 0;\n StringBuilder str = new StringBuilder();\n\n for(int i = 0; i<s.length(); i++){\n if( s.charAt(i) == \'(\'){\n count++;\n if(count>=2) str.append(\'(\'... | 5 | 0 | ['Java'] | 0 |
remove-outermost-parentheses | C++ Easy understandable solution using stack | c-easy-understandable-solution-using-sta-hr6f | \nstring removeOuterParentheses(string s) {\n stack<char>s1;\n string ans="";\n for(int i=0;i<s.size();i++)\n {\n if(s[i] | Kalim123 | NORMAL | 2022-03-18T06:08:24.450061+00:00 | 2022-03-18T06:08:24.450087+00:00 | 556 | false | ```\nstring removeOuterParentheses(string s) {\n stack<char>s1;\n string ans="";\n for(int i=0;i<s.size();i++)\n {\n if(s[i]==\'(\')\n {\n if(s1.size()>0)\n ans+=\'(\';\n s1.push(\'(\');\n }else\n {\... | 5 | 0 | ['Stack', 'C', 'C++'] | 0 |
remove-outermost-parentheses | Javascript Stack oriented solution | javascript-stack-oriented-solution-by-kr-bz4s | var removeOuterParentheses = function(S) {\n\n let stack = [];\n let result = \'\';\n for (const s of S) {\n if( s === \'(\') {\n if (s | kraiymbek | NORMAL | 2021-06-30T14:46:35.152731+00:00 | 2021-06-30T14:46:35.152774+00:00 | 349 | false | var removeOuterParentheses = function(S) {\n\n let stack = [];\n let result = \'\';\n for (const s of S) {\n if( s === \'(\') {\n if (stack.length) {\n result+=s;\n }\n stack.push(s);\n } else {\n stack.pop();\n if (stack.length) {\n ... | 5 | 0 | ['JavaScript'] | 1 |
remove-outermost-parentheses | python simple solution speed 98.46% and memory 99.39% | python-simple-solution-speed-9846-and-me-brfu | \nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n ans = []\n l = []\n count = 0\n for i in S:\n l | baranee18 | NORMAL | 2021-05-15T08:45:48.352406+00:00 | 2021-06-06T08:46:13.180509+00:00 | 389 | false | ```\nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n ans = []\n l = []\n count = 0\n for i in S:\n l.append(i)\n if i == \'(\':\n count+= 1\n else:\n count -= 1\n if count == 0:\n ... | 5 | 0 | ['Python'] | 0 |
remove-outermost-parentheses | C++ | Faster than 100% | Easy | c-faster-than-100-easy-by-pranjalb-30vq | A simple iterative program that iterates on the string.\nWe use a variable flag to cound the number of left parenthesis. Since we just have to remove one parent | pranjalb | NORMAL | 2020-12-01T06:29:30.785592+00:00 | 2020-12-01T06:29:30.785643+00:00 | 506 | false | A simple iterative program that iterates on the string.\nWe use a variable flag to cound the number of left parenthesis. Since we just have to remove one parenthesis only, we check if the flag value is greater than 1, and then add characters to the resultant string.\n\n```\nConsider the following test case\n\n\tS = "((... | 5 | 0 | ['C', 'C++'] | 0 |
remove-outermost-parentheses | Simple Java Solution | simple-java-solution-by-kumarpallav-s26q | \nclass Solution {\n public String removeOuterParentheses(String S) {\n \n \tchar [] chars=S.toCharArray();\n \tStringBuilder sb=new StringBuil | kumarpallav | NORMAL | 2020-08-10T11:25:31.520694+00:00 | 2020-08-10T11:25:31.520739+00:00 | 985 | false | ```\nclass Solution {\n public String removeOuterParentheses(String S) {\n \n \tchar [] chars=S.toCharArray();\n \tStringBuilder sb=new StringBuilder();\n \tStack<Character> st= new Stack<>();\n \tint startindex=0;\n \tfor ( int i=0;i<chars.length;i++ ) {\n \t\tchar c= chars[i];\n \t\tif... | 5 | 0 | ['Java'] | 2 |
remove-outermost-parentheses | Simple String operation....No STACKS USED....Easy to Understand | simple-string-operationno-stacks-usedeas-3pkf | \nclass Solution {\n public String removeOuterParentheses(String S) {\n String k="",s="";int c=0,d=0;// c-> to count no. of \'(\' and d->no. of \')\' | jayantbabu2868 | NORMAL | 2020-05-25T09:41:22.497087+00:00 | 2020-05-25T09:41:22.497140+00:00 | 435 | false | ```\nclass Solution {\n public String removeOuterParentheses(String S) {\n String k="",s="";int c=0,d=0;// c-> to count no. of \'(\' and d->no. of \')\' \n for(int i=0;i<S.length();i++)\n {\n if(S.charAt(i)==\'(\'){\n s=s+\'(\';\n c++;\n }\n ... | 5 | 0 | ['String', 'Java'] | 1 |
remove-outermost-parentheses | C solution | c-solution-by-zhaoyaqiong-33zj | \nchar * removeOuterParentheses(char * S){\n char *str = malloc(sizeof(char) * strlen(S));\n int flag = 0,p = 0;\n for (int i = 0;i < strlen(S); i++) { | zhaoyaqiong | NORMAL | 2020-01-20T09:00:32.215745+00:00 | 2020-01-20T09:00:32.215792+00:00 | 490 | false | ```\nchar * removeOuterParentheses(char * S){\n char *str = malloc(sizeof(char) * strlen(S));\n int flag = 0,p = 0;\n for (int i = 0;i < strlen(S); i++) {\n if (S[i]==\'(\') {\n flag++;\n if (flag != 1) {\n str[p++] = S[i];\n }\n }else{\n ... | 5 | 0 | [] | 0 |
remove-outermost-parentheses | C# | c-by-mhorskaya-smkh | \npublic string RemoveOuterParentheses(string S) {\n\tvar str = new StringBuilder();\n\tvar i = 0;\n\n\tforeach (var c in S.ToCharArray()) {\n\t\ti += c == \'(\ | mhorskaya | NORMAL | 2020-01-02T08:48:25.184738+00:00 | 2020-01-02T08:48:25.184790+00:00 | 360 | false | ```\npublic string RemoveOuterParentheses(string S) {\n\tvar str = new StringBuilder();\n\tvar i = 0;\n\n\tforeach (var c in S.ToCharArray()) {\n\t\ti += c == \'(\' ? 1 : -1;\n\n\t\tif (c == \'(\' && i > 1 || c == \')\' && i > 0)\n\t\t\tstr.Append(c);\n\t}\n\n\treturn str.ToString();\n}\n``` | 5 | 1 | [] | 1 |
remove-outermost-parentheses | javascript | javascript-by-suxiaohui1996-8l7b | \nvar removeOuterParentheses = function(S) {\n let res = \'\',\n leftNum = 0;\n for(let i = 0; i < S.length; ++i) {\n if(S.charAt(i) == \'(\ | suxiaohui1996 | NORMAL | 2019-04-08T02:08:24.646844+00:00 | 2019-04-08T02:08:24.646880+00:00 | 827 | false | ```\nvar removeOuterParentheses = function(S) {\n let res = \'\',\n leftNum = 0;\n for(let i = 0; i < S.length; ++i) {\n if(S.charAt(i) == \'(\') {\n leftNum ++;\n if(leftNum == 2) {\n while(leftNum > 0) {\n res += S.charAt(i);\n ... | 5 | 0 | [] | 0 |
remove-outermost-parentheses | Python // C++ // Haskell Solutions | python-c-haskell-solutions-by-code_repor-pw9c | Video Explanation: https://www.youtube.com/watch?v=ekdNNn3vOqQ\n\n1. Group by parentheses substring when LEFT = RIGHT\n2. Then just shave off the first and last | code_report | NORMAL | 2019-04-07T04:01:38.032094+00:00 | 2019-04-07T04:01:38.032136+00:00 | 674 | false | **Video Explanation:** https://www.youtube.com/watch?v=ekdNNn3vOqQ\n\n1. Group by parentheses substring when LEFT = RIGHT\n2. Then just shave off the first and last parentheses of each group and rejoin\n\n**Python Solution 1:**\n```\ndef group(S):\n\tt, a, l = 0, 0, []\n for i in range(len(S)):\n t = t + 1 if... | 5 | 0 | ['C', 'Python'] | 0 |
remove-outermost-parentheses | 100% Beat, C++ Solution using stack, Time and space complexity -O(n) | 100-beat-c-solution-using-stack-time-and-q025 | IntuitionThe problem requires us to remove the outermost parentheses of every valid primitive string in the input. A primitive string is a valid, non-empty pare | cbirla14 | NORMAL | 2025-03-10T14:28:30.235227+00:00 | 2025-03-10T14:28:30.235227+00:00 | 415 | false | # Intuition
The problem requires us to remove the outermost parentheses of every valid primitive string in the input. A primitive string is a valid, non-empty parenthesis substring that cannot be split further.
The key observation is that the first and last parentheses of each valid primitive group should be removed. ... | 4 | 0 | ['String', 'Stack', 'C++'] | 0 |
remove-outermost-parentheses | Removing Outer Layers of Parentheses in Linear Time || 4ms Runtime | removing-outer-layers-of-parentheses-in-564fk | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is about removing the outermost parentheses from a valid string of parenthe | somyaParikh | NORMAL | 2024-08-24T17:05:48.200276+00:00 | 2024-08-24T17:05:48.200331+00:00 | 1,255 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is about removing the outermost parentheses from a valid string of parentheses. The idea is that for each balanced section of the string (or primitive), you want to remove the first opening parenthesis ( and the last closing p... | 4 | 0 | ['String', 'Python', 'C++', 'Java', 'JavaScript'] | 0 |
remove-outermost-parentheses | SIMPLE STACK COMMENTED C++ SOLUTION | simple-stack-commented-c-solution-by-jef-i82c | 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 | Jeffrin2005 | NORMAL | 2024-07-24T12:58:00.120363+00:00 | 2024-07-24T12:58:00.120399+00:00 | 843 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:o(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(n)\n<!-- Add your space complexity here, e.g. $$O... | 4 | 0 | ['C++'] | 0 |
remove-outermost-parentheses | Easy Solution 🧩 A Step-by-Step Guide in Java, Python, and C++ 📚 | easy-solution-a-step-by-step-guide-in-ja-y7yh | Intuition\nTo solve the problem of removing outermost parentheses, the main idea is to track the balance of parentheses using a counter. When traversing the str | prashu1818 | NORMAL | 2024-07-08T19:25:44.534848+00:00 | 2024-07-08T19:25:44.534881+00:00 | 882 | false | # Intuition\nTo solve the problem of removing outermost parentheses, the main idea is to track the balance of parentheses using a counter. When traversing the string, we use the counter to determine if the current parenthesis is part of the outermost pair. If it is not, we add it to the result string.\n\n# Approach\n1.... | 4 | 0 | ['String', 'C++', 'Java', 'Python3'] | 2 |
remove-outermost-parentheses | Explained || Optimized || Interview Question || C++ | explained-optimized-interview-question-c-3ygz | Intuition\n Describe your first thoughts on how to solve this problem. \nitna to samjh aa jaata hai saab, 350 ques karne k baad\n\n# Approach\n Describe your ap | satwikjain104 | NORMAL | 2023-07-17T14:38:47.652982+00:00 | 2023-07-17T14:38:47.653005+00:00 | 547 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nitna to samjh aa jaata hai saab, 350 ques karne k baad\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\njust use the stack \n\n# Complexity\n- Time complexity:\nO(n), n is size of given string\n\n- Space complexity:... | 4 | 0 | ['C++'] | 1 |
remove-outermost-parentheses | ✅ Aesthetic TypeScript | aesthetic-typescript-by-mlajkim-j3vh | Code\nts\nfunction removeOuterParentheses(s: string): string {\n let level = 0\n let built: string = ""\n for (const c of s) {\n if (c === "(" & | mlajkim | NORMAL | 2023-07-09T19:55:22.098705+00:00 | 2023-07-09T19:55:22.098728+00:00 | 109 | false | # Code\n```ts\nfunction removeOuterParentheses(s: string): string {\n let level = 0\n let built: string = ""\n for (const c of s) {\n if (c === "(" && level++ === 0) continue\n if (c === ")" && level-- === 1) continue\n built += c\n }\n return built\n};\n```\n\n# Thank you\nUpvote if... | 4 | 0 | ['TypeScript'] | 0 |
remove-outermost-parentheses | C++ EASY AND CLEAN CODE | c-easy-and-clean-code-by-arpiii_7474-9ksq | Code\n\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n stack<char> st;\n string res="";\n for(int i=0;i<s.size( | arpiii_7474 | NORMAL | 2023-06-28T04:18:46.990281+00:00 | 2023-06-28T04:18:46.990312+00:00 | 1,471 | false | # Code\n```\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n stack<char> st;\n string res="";\n for(int i=0;i<s.size();i++){\n if(s[i]==\'(\' && st.empty()){\n st.push(s[i]);\n }\n else if(s[i]==\'(\'){\n st.p... | 4 | 0 | ['C++'] | 2 |
remove-outermost-parentheses | [ Python ] | Simple & Clean Solution | python-simple-clean-solution-by-yash_vis-vekh | Code\n\nclass Solution:\n def removeOuterParentheses(self, s: str) -> str:\n ans, cnt = [], 0\n for ch in s:\n if ch == \'(\' and cn | yash_visavadia | NORMAL | 2023-05-02T16:36:02.038554+00:00 | 2023-05-02T16:36:02.038601+00:00 | 1,553 | false | # Code\n```\nclass Solution:\n def removeOuterParentheses(self, s: str) -> str:\n ans, cnt = [], 0\n for ch in s:\n if ch == \'(\' and cnt > 0: ans.append(ch)\n if ch == \')\' and cnt > 1: ans.append(ch)\n cnt += 1 if ch == \'(\' else -1\n return "".join(ans)\n``... | 4 | 1 | ['Python3'] | 0 |
remove-outermost-parentheses | Easily Understandable JAVA Stack & Without Stack sol. | easily-understandable-java-stack-without-8nn7 | 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 | harsh_tiwari_ | NORMAL | 2023-04-22T16:42:18.325789+00:00 | 2023-04-22T16:42:18.325820+00:00 | 1,263 | 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)$$ --... | 4 | 0 | ['Java'] | 0 |
remove-outermost-parentheses | Go(golang) solution | gogolang-solution-by-azizjon003-2utj | \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) \n\n# Code\n\n | Azizjon003 | NORMAL | 2023-04-10T18:12:11.193076+00:00 | 2023-04-10T18:12:11.193116+00:00 | 554 | false | \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)$$ -->\n\n# Code\n```\nfunc removeOuterParentheses(s string) string {\n var result string\n var index int\n\n for _, x := range s {\n switch x... | 4 | 0 | ['Array', 'Go'] | 0 |
remove-outermost-parentheses | O(N) solution using stack|beats 100% | C++ | on-solution-using-stackbeats-100-c-by-kg-jyn3 | Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n\n | kgharat008769321 | NORMAL | 2023-03-08T14:13:27.300834+00:00 | 2023-03-08T14:13:27.300866+00:00 | 879 | false | # Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n string removeOuterParentheses(string s) {\n\n stack<char> st;\n string ans="";\n\n for(auto c: s){\n\n if(!st.empty()) ans+=c;\n if(c==\'(\') st.push(c);\n ... | 4 | 0 | ['C++'] | 0 |
remove-outermost-parentheses | clean, readable code [C++] | clean-readable-code-c-by-vishshukla-l4m6 | Intuition\nEasy one-liner in C++\n\n# Approach\nYou don\'t need Python, when you know C++ like me\n\n# Complexity\n- Time complexity: O(-1)\n\n- Space complexit | vishshukla | NORMAL | 2023-02-10T21:44:42.054142+00:00 | 2023-02-10T21:45:38.527281+00:00 | 1,011 | false | # Intuition\nEasy one-liner in C++\n\n# Approach\nYou don\'t need Python, when you know C++ like me\n\n# Complexity\n- Time complexity: O(-1)\n\n- Space complexity: O(inf)\n\n# Code\n```\nclass Solution {public:string removeOuterParentheses(string s) {string output;int count = 0;for (auto c : s) {if (c == \')\') count-... | 4 | 0 | ['C++'] | 6 |
remove-outermost-parentheses | C++|faster code | cfaster-code-by-praduman_singh-5nci | 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 | praduman_Singh | NORMAL | 2022-11-21T18:51:54.131563+00:00 | 2022-11-21T18:51:54.131599+00:00 | 810 | 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. $... | 4 | 0 | ['String', 'Stack', 'C++'] | 0 |
remove-outermost-parentheses | JAVASCRIPT easy stepwise | javascript-easy-stepwise-by-ankitguria14-iv4o | \n let count = 0, outer = ""\n \n for(let i = 0 ; i < s.length; i++) {\n if(s[i] === "(") {\n count++\n }\n if(count > | ankitguria142 | NORMAL | 2022-03-13T17:10:46.477385+00:00 | 2022-03-13T17:10:46.477446+00:00 | 466 | false | \n let count = 0, outer = ""\n \n for(let i = 0 ; i < s.length; i++) {\n if(s[i] === "(") {\n count++\n }\n if(count > 1) {\n outer += s[i]\n }\n if(s[i] === ")") {\n count--\n }\n }\n return outer\n | 4 | 0 | ['JavaScript'] | 0 |
remove-outermost-parentheses | Java || Easy to understand | java-easy-to-understand-by-arabboyismoil-83ek | \nclass Solution {\n public String removeOuterParentheses(String s) {\n int count=0, start=0;\n StringBuilder res= new StringBuilder();\n | arabboyismoilov | NORMAL | 2021-10-12T16:02:27.619348+00:00 | 2021-10-12T16:02:27.619392+00:00 | 377 | false | ```\nclass Solution {\n public String removeOuterParentheses(String s) {\n int count=0, start=0;\n StringBuilder res= new StringBuilder();\n \n for(int i=0; i<s.length(); i++){\n if(s.charAt(i)==\'(\')\n count++;\n else\n count--;\n\t\t\... | 4 | 0 | ['Java'] | 2 |
remove-outermost-parentheses | Java solution 5 lines, faster and less memory than 99% (example also in C++, Python) | java-solution-5-lines-faster-and-less-me-mw2l | Although this problem is labeled as \'easy\' it can seem quite difficult at first, especially due to the way the writeup was written.\n\nHere is an advice, whic | Njall | NORMAL | 2021-07-25T10:39:02.188027+00:00 | 2021-07-25T10:54:22.907909+00:00 | 147 | false | Although this problem is labeled as \'easy\' it can seem quite difficult at first, especially due to the way the writeup was written.\n\nHere is an advice, which has always helped me break down parenthesis problems. There is something called Catalan structures or Catalan numbers. Now, bear with me! This might seem awfu... | 4 | 0 | [] | 0 |
remove-outermost-parentheses | Simple Go and Java solutions | simple-go-and-java-solutions-by-nathanna-ulwl | Java:\n\n\npublic String removeOuterParentheses(String S) {\n\tStringBuilder s = new StringBuilder();\n\tStack<Character> h = new Stack<>();\n\n\tfor (int i = 0 | nathannaveen | NORMAL | 2021-02-01T15:04:27.637383+00:00 | 2021-02-01T15:04:27.637435+00:00 | 688 | false | Java:\n\n```\npublic String removeOuterParentheses(String S) {\n\tStringBuilder s = new StringBuilder();\n\tStack<Character> h = new Stack<>();\n\n\tfor (int i = 0; i < S.length(); i++) {\n\t\tif (h.size() == 1 && S.charAt(i) == \')\'){\n\t\t\th.pop();\n\t\t\tcontinue;\n\t\t}\n\t\telse if (h.size() == 0 && S.charAt(i) ... | 4 | 0 | ['Java', 'Go'] | 0 |
remove-outermost-parentheses | Java solution with stack and explanation | java-solution-with-stack-and-explanation-gejp | This works because if the parentheses is outer most and it is a closing parenthese then the size of the stack has to be equal to one. If the parenthese is openi | nathannaveen | NORMAL | 2020-12-10T14:40:35.708693+00:00 | 2021-08-08T13:44:50.098647+00:00 | 769 | false | This works because if the parentheses is outer most and it is a closing parenthese then the size of the stack has to be equal to one. If the parenthese is opening then the size should be 0. Other wise they are inear parentheses.\n```\npublic String removeOuterParentheses(String S) {\n\tStringBuilder s = new StringBuild... | 4 | 0 | ['Stack', 'Java'] | 2 |
remove-outermost-parentheses | Easy way explanation every step | easy-way-explanation-every-step-by-paul_-l8bq | if your current char is \'(\' then two things happen one is stack is empty then don\'t add char in result means it indicates no outer parentheses is present.if | paul_dream | NORMAL | 2020-11-14T06:35:22.549689+00:00 | 2020-11-14T06:53:35.656724+00:00 | 163 | false | # if your current char is \'(\' then two things happen one is stack is empty then don\'t add char in result means it indicates no outer parentheses is present.if your stack is not empty then definitely have a outer parentheses this time add char into results\n```\nif c == \'(\':\n if stack:\n ... | 4 | 0 | ['Python'] | 0 |
remove-outermost-parentheses | Concept of these kind of problems | Simple | | concept-of-these-kind-of-problems-simple-iurm | problem similar to Google Hashcode 2020 Qualification round\nThe key in these types of problems is to have a variable named depth, and increment and decrement i | IamVaibhave53 | NORMAL | 2020-04-09T09:45:46.621622+00:00 | 2020-12-15T06:24:23.342552+00:00 | 150 | false | problem similar to Google Hashcode 2020 Qualification round\nThe key in these types of problems is to have a variable named depth, and increment and decrement it accordingly [ \'(\' depth increases ] \nHere whenver the depth is currently zero we ignore it, and when it is again going to be zero after a series of open an... | 4 | 0 | [] | 2 |
remove-outermost-parentheses | C++ using stack | c-using-stack-by-leenabhandari1-eahv | \nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n stack<char> ss;\n string ans = "";\n \n for(char c: S) | leenabhandari1 | NORMAL | 2020-01-18T18:19:50.077714+00:00 | 2020-01-18T18:19:50.077763+00:00 | 259 | false | ```\nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n stack<char> ss;\n string ans = "";\n \n for(char c: S) {\n if(ss.empty() && c==\'(\') {\n ss.push(c);\n } else if(ss.size() == 1 && c==\')\') {\n ss.pop();\n ... | 4 | 0 | [] | 0 |
remove-outermost-parentheses | Haskell Wins! 1-liner | haskell-wins-1-liner-by-code_report-umh9 | This is why Haskell is so beautiful:\n\nsolve :: String -> String\nsolve = concat \n . map (tail . init) \n . groupBy (\\a b -> [a,b] /= ")(")\n\nThe | code_report | NORMAL | 2019-08-13T21:30:09.177325+00:00 | 2019-08-13T21:30:09.177366+00:00 | 526 | false | This is why Haskell is so beautiful:\n```\nsolve :: String -> String\nsolve = concat \n . map (tail . init) \n . groupBy (\\a b -> [a,b] /= ")(")\n```\nThe one-liner would be:\n```\nsolve = concat . map (tail . init) . groupBy (\\a b -> [a,b] /= ")(")\n``` | 4 | 0 | [] | 0 |
remove-outermost-parentheses | python3 40ms beas 93% | python3-40ms-beas-93-by-jianquanwang-9xna | time complexity : O(n)\n\nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n if len(S) <= 2:\n return ""\n \n | jianquanwang | NORMAL | 2019-07-01T17:43:48.772567+00:00 | 2019-07-01T17:43:48.772623+00:00 | 167 | false | time complexity : O(n)\n```\nclass Solution:\n def removeOuterParentheses(self, S: str) -> str:\n if len(S) <= 2:\n return ""\n \n ans = ""\n count = 0\n for c in S:\n if c == "(":\n count += 1\n if count > 1:\n ... | 4 | 0 | [] | 0 |
remove-outermost-parentheses | java solution | java-solution-by-user7409dy-gso1 | \nclass Solution {\n public String removeOuterParentheses(String S) {\n if(S == null) return "";\n char[] chars = S.toCharArray();\n int | user7409dy | NORMAL | 2019-06-22T06:26:48.069046+00:00 | 2019-06-22T06:26:48.069089+00:00 | 451 | false | ```\nclass Solution {\n public String removeOuterParentheses(String S) {\n if(S == null) return "";\n char[] chars = S.toCharArray();\n int stack = 0;\n\n StringBuilder builder = new StringBuilder();\n for(int i=0; i<chars.length; i++){\n if (chars[i] == 40) {\n ... | 4 | 0 | [] | 0 |
remove-outermost-parentheses | C++ solution using One stack and One queue. | c-solution-using-one-stack-and-one-queue-wx7s | \nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n stack<char> open;\n queue<char> primitive;\n string output;\n | hsuyaagnihotri | NORMAL | 2019-04-07T05:42:11.626717+00:00 | 2019-04-07T05:42:11.626757+00:00 | 507 | false | ```\nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n stack<char> open;\n queue<char> primitive;\n string output;\n for(int i=0; i<S.length(); i++) {\n primitive.push(S[i]);\n if(S[i] == \'(\') {\n open.push(S[i]);\n }... | 4 | 1 | ['C', 'C++'] | 1 |
remove-outermost-parentheses | java O(N) one scan no stack | java-on-one-scan-no-stack-by-noteanddata-grv7 | http://www.noteanddata.com/leetcode-1021-Remove-Outermost-Parentheses-java-solution-note.html\n\n\n public String removeOuterParentheses(String S) {\n | noteanddata | NORMAL | 2019-04-07T04:05:34.943455+00:00 | 2019-04-07T04:05:34.943497+00:00 | 511 | false | http://www.noteanddata.com/leetcode-1021-Remove-Outermost-Parentheses-java-solution-note.html\n\n```\n public String removeOuterParentheses(String S) {\n int count = 0;\n int last = 0;\n StringBuilder sb = new StringBuilder();\n for(int i = 0; i < S.length(); ++i) {\n if(S.char... | 4 | 2 | [] | 0 |
consecutive-characters | [Python] One line | python-one-line-by-lee215-rw6l | \nPython:\npy\n def maxPower(self, s):\n return max(len(list(b)) for a, b in itertools.groupby(s))\n\n | lee215 | NORMAL | 2020-05-16T16:02:57.709396+00:00 | 2020-05-16T16:02:57.709453+00:00 | 5,699 | false | \n**Python:**\n```py\n def maxPower(self, s):\n return max(len(list(b)) for a, b in itertools.groupby(s))\n```\n | 79 | 6 | [] | 16 |
consecutive-characters | [Java/Python 3] Simple code w/ brief explanation and analysis. | javapython-3-simple-code-w-brief-explana-t9l1 | Increase the counter by 1 if current char same as the previous one; otherwise, reset the counter to 1;\n2. Update the max value of the counter during each itera | rock | NORMAL | 2020-05-16T16:04:25.965810+00:00 | 2022-05-01T01:26:52.094030+00:00 | 7,149 | false | 1. Increase the counter by 1 if current char same as the previous one; otherwise, reset the counter to 1;\n2. Update the max value of the counter during each iteration.\n\n```java\n public int maxPower(String s) {\n int ans = 1;\n for (int i = 1, cnt = 1; i < s.length(); ++i) {\n if (s.charA... | 76 | 0 | [] | 14 |
consecutive-characters | ✅ [C++/Python] 3 Simple Solutions w/ Explanation | Brute-Force + Sliding Window + Single-Pass | cpython-3-simple-solutions-w-explanation-26bc | We need to return length of longest substring consisting of only one character\n\n---\n\n\u2714\uFE0F Solution - I (Brute-Force)\n\nWe can start at each charact | archit91 | NORMAL | 2021-12-13T02:43:51.958082+00:00 | 2021-12-13T07:35:08.064280+00:00 | 2,532 | false | We need to return length of longest substring consisting of only one character\n\n---\n\n\u2714\uFE0F ***Solution - I (Brute-Force)***\n\nWe can start at each character in `s` and try to form longest substring from there which consists of only one character. If we find that the current character is not same as previous... | 45 | 4 | [] | 5 |
consecutive-characters | [Python] Oneliner using groupby, explained | python-oneliner-using-groupby-explained-nxj1u | What you need to do in this problem is just iterate over string and find groups of equal symbols, and then return the length of the longest group. Natural way t | dbabichev | NORMAL | 2020-11-03T08:53:26.612272+00:00 | 2021-12-13T09:06:26.509373+00:00 | 992 | false | What you need to do in this problem is just iterate over string and find groups of equal symbols, and then return the length of the longest group. Natural way to do it is to use functionality of itertools library, more precisely `groupby` function. By definition, if we do not specify arguments for groupby, it will crea... | 32 | 2 | [] | 0 |
consecutive-characters | [JavaScript] Easy Sliding Window With Explanation & Analysis - O(n) time O(1) space | javascript-easy-sliding-window-with-expl-4fvj | Explanation:\n1. Increase the size of the window by incrementing the end index.\n2. After each increment, check if the size of the window (end - start + 1) is g | vine9 | NORMAL | 2020-05-16T18:50:48.004653+00:00 | 2020-05-16T19:48:03.298536+00:00 | 1,205 | false | **Explanation:**\n1. Increase the size of the window by incrementing the end index.\n2. After each increment, check if the size of the window ```(end - start + 1)``` is greater than the current max size (power). \n3. Repeat steps 1 and 2 until the start and end characters of the window are no longer equal, then move to... | 18 | 0 | ['JavaScript'] | 1 |
consecutive-characters | [C++] 2 Pointers Optimised Solution Discussed and Explained, 100% Time, 100% Space | c-2-pointers-optimised-solution-discusse-2rrq | This problem is basically asking us to find the longest substring with a given condition - all the characters being the same.\n\nAnd while there are countless s | ajna | NORMAL | 2020-11-03T10:31:53.755158+00:00 | 2020-11-03T10:39:03.846461+00:00 | 2,109 | false | This problem is basically asking us to find the longest substring with a given condition - all the characters being the same.\n\nAnd while there are countless substring problems and even more so approaches you might use to solve them, this one is particularly suited for a straightforward approach using 2 pointers - one... | 17 | 0 | ['Two Pointers', 'C', 'C++'] | 5 |
consecutive-characters | C++ EASY TO SOLVE || Beginner Friendly with a detailed explanation || Time-O(n) and Space-O(1) | c-easy-to-solve-beginner-friendly-with-a-y23w | Two Pointer Approach || Time-O(n) and Space-O(1)\n\nIntuition:\nAfter reading this question we got the gist ,that we need to find out the longest consecutive ch | Cosmic_Phantom | NORMAL | 2021-12-13T02:14:59.931447+00:00 | 2024-08-23T02:43:12.683528+00:00 | 1,136 | false | # **Two Pointer Approach || Time-O(n) and Space-O(1)**\n\n**Intuition:**\nAfter reading this question we got the gist ,that we need to find out the longest consecutive character sequence of same letter\n\n*For example:*\n```\nInput: s = "abbcccddddeeeeedcba"\nOutput: 5\nExplanation: The substring "eeeee" is of length 5... | 16 | 9 | ['Two Pointers', 'C', 'C++'] | 1 |
consecutive-characters | easy faster than 90% cpp solution | easy-faster-than-90-cpp-solution-by-jink-m937 | \nclass Solution {\npublic:\n int maxPower(string s) {\n size_t max = 1;\n size_t curr = 1;\n for (size_t i = 1; i < s.size(); i++) {\n | jinkim | NORMAL | 2020-06-26T22:06:57.241649+00:00 | 2020-06-26T22:06:57.241698+00:00 | 1,329 | false | ```\nclass Solution {\npublic:\n int maxPower(string s) {\n size_t max = 1;\n size_t curr = 1;\n for (size_t i = 1; i < s.size(); i++) {\n if (s[i - 1] == s[i]) curr++;\n else {\n if (curr > max) max = curr;\n curr = 1;\n }\n ... | 12 | 0 | ['C', 'C++'] | 2 |
consecutive-characters | C++ Super Easy, Short and Simple One-Pass Solution | c-super-easy-short-and-simple-one-pass-s-r4nt | \nclass Solution {\npublic:\n int maxPower(string s) {\n int max_len = 0, curr_len = 0;\n char prev = s[0];\n \n for (auto letter | yehudisk | NORMAL | 2021-12-13T09:04:15.715178+00:00 | 2021-12-13T09:04:15.715222+00:00 | 1,054 | false | ```\nclass Solution {\npublic:\n int maxPower(string s) {\n int max_len = 0, curr_len = 0;\n char prev = s[0];\n \n for (auto letter : s){\n if (letter == prev)\n curr_len++;\n else\n curr_len = 1;\n \n max_len = ma... | 11 | 3 | ['C'] | 1 |
consecutive-characters | Python O(n) by linear scan. [w/ Comment] | python-on-by-linear-scan-w-comment-by-br-ifwf | Python O(n) by linear scan.\n\n---\n\n\nclass Solution:\n def maxPower(self, s: str) -> int:\n \n # the minimum value for consecutive is 1\n | brianchiang_tw | NORMAL | 2020-05-17T13:57:38.917815+00:00 | 2020-05-17T13:57:38.917858+00:00 | 1,792 | false | Python O(n) by linear scan.\n\n---\n\n```\nclass Solution:\n def maxPower(self, s: str) -> int:\n \n # the minimum value for consecutive is 1\n local_max, global_max = 1, 1\n \n # dummy char for initialization\n prev = \'#\'\n for char in s:\n \n ... | 11 | 0 | ['String', 'Iterator', 'Python', 'Python3'] | 5 |
consecutive-characters | [Java] O(n) time O(1) space | java-on-time-o1-space-by-manrajsingh007-mnfp | ```\nclass Solution {\n public int maxPower(String s) {\n int n = s.length();\n int start = 0, end = 0, max = 0;\n while(end < n) {\n | manrajsingh007 | NORMAL | 2020-05-16T16:00:59.562341+00:00 | 2020-05-16T16:07:30.203630+00:00 | 1,656 | false | ```\nclass Solution {\n public int maxPower(String s) {\n int n = s.length();\n int start = 0, end = 0, max = 0;\n while(end < n) {\n while(end < n && s.charAt(end) == s.charAt(start)) {\n max = Math.max(max, end - start + 1);\n end++;\n }\n ... | 11 | 3 | [] | 0 |
consecutive-characters | Easy python solution | easy-python-solution-by-vistrit-tm6k | \ndef maxPower(self, s: str) -> int:\n c,ans = 1,1\n for i in range(len(s)-1):\n if s[i]==s[i+1]:\n c+=1\n | vistrit | NORMAL | 2021-12-13T07:11:06.708362+00:00 | 2021-12-13T07:11:06.708395+00:00 | 1,374 | false | ```\ndef maxPower(self, s: str) -> int:\n c,ans = 1,1\n for i in range(len(s)-1):\n if s[i]==s[i+1]:\n c+=1\n ans=max(c,ans)\n else:\n c=1\n return ans\n``` | 9 | 0 | ['Python', 'Python3'] | 1 |
consecutive-characters | Java Simple Approach O(n) Time, O(1) Space | java-simple-approach-on-time-o1-space-by-sekx | If next character is same increase the current counter. Else reset the current counter to 1 when a different character is encountered. \n\nclass Solution {\n | danielrechey28 | NORMAL | 2020-05-16T16:07:42.430657+00:00 | 2020-05-16T16:19:57.014277+00:00 | 1,210 | false | If next character is same increase the current counter. Else reset the current counter to 1 when a different character is encountered. \n```\nclass Solution {\n public int maxPower(String s) {\n int len=s.length();\n int count =0;\n int curr=1;\n for(int i=0;i<len;i++){\n if(i<... | 8 | 0 | ['Java'] | 0 |
consecutive-characters | EASIEST APPROACH 🤤||✅ 💯% ON RUNTIME ||✌️😎 WITH EXPLNATION | easiest-approach-on-runtime-with-explnat-t96j | Intuition\nThe problem asks to find the maximum consecutive occurrences of the same character in the given string s.\n\n# Approach\nWe can iterate through the c | IamHazra | NORMAL | 2024-03-01T13:48:54.507813+00:00 | 2024-03-01T13:48:54.507838+00:00 | 281 | false | # Intuition\nThe problem asks to find the maximum consecutive occurrences of the same character in the given string `s`.\n\n# Approach\nWe can iterate through the characters of the string `s` and keep track of the count of consecutive occurrences of the same character. We use two variables, `count` to keep track of the... | 7 | 0 | ['String', 'Counting', 'Java'] | 1 |
consecutive-characters | [C++] One Pass | c-one-pass-by-orangezeit-7lk3 | cpp\nclass Solution {\npublic:\n int maxPower(string s) {\n int ans(1), k(0);\n s += \'*\';\n for (int i = 0; i + 1 < s.length(); ++i)\n | orangezeit | NORMAL | 2020-05-16T16:20:32.600311+00:00 | 2020-05-16T16:20:32.600346+00:00 | 1,056 | false | ```cpp\nclass Solution {\npublic:\n int maxPower(string s) {\n int ans(1), k(0);\n s += \'*\';\n for (int i = 0; i + 1 < s.length(); ++i)\n if (s[i] != s[i + 1]) {\n ans = max(ans, i + 1 - k);\n k = i + 1;\n }\n return ans;\n }\n};\n`... | 7 | 1 | [] | 0 |
consecutive-characters | Easy c++ solution with comments | easy-c-solution-with-comments-by-sarnava-akqu | \nclass Solution {\npublic:\n int maxPower(string s) {\n //ans will store the final ans and now will store the current answer\n int ans = INT_M | sarnava | NORMAL | 2020-05-16T16:07:21.405661+00:00 | 2020-05-16T16:19:58.874479+00:00 | 549 | false | ```\nclass Solution {\npublic:\n int maxPower(string s) {\n //ans will store the final ans and now will store the current answer\n int ans = INT_MIN, now = 1;\n \n for(int i = 0;i<s.length();i++){\n //if the current char is the same as the next char then increase now\n ... | 7 | 1 | [] | 1 |
consecutive-characters | Java | 100% Faster | Explained | Simplest Solution | O(N) | java-100-faster-explained-simplest-solut-xgrp | We will be checking if subsequent characters are equal, if yes we will keep on incrementing the count otherwise we will store the new value in max if count > ma | rounak2k | NORMAL | 2021-12-13T05:39:40.357608+00:00 | 2021-12-13T06:04:17.671833+00:00 | 1,030 | false | We will be checking if subsequent characters are equal, if yes we will keep on incrementing the count otherwise we will store the new value in max if count > max.\n```\nclass Solution {\n public int maxPower(String s) {\n\t\t// Taking max & count as 1 since minimum length of substring can be 1\n int max = 1, ... | 6 | 1 | ['Java'] | 4 |
consecutive-characters | Clean JavaScript Solution | clean-javascript-solution-by-shimphillip-bpgj | \n// time O(n^2) space O(1)\nvar maxPower = function(s) {\n let max = 1\n let count = 1\n \n for(let i=0; i<s.length - 1; i++) {\n if(s[i] == | shimphillip | NORMAL | 2020-11-10T21:55:34.175930+00:00 | 2020-12-03T04:07:28.764713+00:00 | 572 | false | ```\n// time O(n^2) space O(1)\nvar maxPower = function(s) {\n let max = 1\n let count = 1\n \n for(let i=0; i<s.length - 1; i++) {\n if(s[i] === s[i+1]) {\n count++\n max = Math.max(count, max)\n } else {\n count = 1\n }\n }\n \n return max\n};... | 6 | 0 | ['JavaScript'] | 1 |
consecutive-characters | simple and easy understanding c++ code | simple-and-easy-understanding-c-code-by-6qzla | \ncpp []\nclass Solution {\npublic:\n int maxPower(string s) {\n int n=s.length();\n int c=1,d=1;\n if(n==0){\n return 0;\n | sampathkumar718 | NORMAL | 2024-09-19T17:18:55.802857+00:00 | 2024-09-19T17:18:55.802882+00:00 | 197 | false | \n```cpp []\nclass Solution {\npublic:\n int maxPower(string s) {\n int n=s.length();\n int c=1,d=1;\n if(n==0){\n return 0;\n }\n for(int i=1;i<n;i++){\n if(s[i]==s[i-1]){\n c++;\n }\n else{\n d=max(d,c);\n ... | 5 | 0 | ['C++'] | 0 |
consecutive-characters | Python ✅✅✅ || Faster than 99.60% || Memory Beats 97.63% | python-faster-than-9960-memory-beats-976-ttym | Code\n\nclass Solution:\n def maxPower(self, s):\n cnt = 0\n m = 0\n for i in range(1, len(s)):\n if (s[i-1] == s[i]): \n | a-fr0stbite | NORMAL | 2022-12-15T02:49:10.106544+00:00 | 2022-12-15T02:49:10.106586+00:00 | 527 | false | # Code\n```\nclass Solution:\n def maxPower(self, s):\n cnt = 0\n m = 0\n for i in range(1, len(s)):\n if (s[i-1] == s[i]): \n cnt += 1\n m = max(cnt, m)\n else: cnt = 0\n return m + 1\n```\n {\n int n = s.size();\n int ans = 1;\n int cnt = 1;\n | spyder_master | NORMAL | 2021-12-13T04:56:47.696444+00:00 | 2021-12-14T05:28:06.176771+00:00 | 145 | false | \n**Solution in c++**\n\n\n```\nclass Solution {\npublic:\n int maxPower(string s) {\n int n = s.size();\n int ans = 1;\n int cnt = 1;\n for(int i = 1; i < n; i++){\n if(s[i] == s[i-1]){\n cnt++;\n }else{\n cnt = 1;\n }\n ... | 5 | 0 | ['String', 'C'] | 0 |
consecutive-characters | [Rust] solution | rust-solution-by-rudy-41h4 | There is no magic here, just iterate over the string and count the length of consecutive substring. \n\n### Rust Solution\nRust\nimpl Solution {\n pub fn max | rudy__ | NORMAL | 2020-05-17T05:37:10.545551+00:00 | 2022-11-19T02:53:18.054120+00:00 | 100 | false | There is no magic here, just iterate over the string and count the length of consecutive substring. \n\n### Rust Solution\n```Rust\nimpl Solution {\n pub fn max_power(s: String) -> i32 {\n let (mut res, mut cnt) = (0, 0);\n let mut pre = \'#\' ;\n for c in s.chars() {\n if c == pre {\n ... | 5 | 0 | [] | 1 |
consecutive-characters | Simple java - 5 lines - O(n) time and O(1) space | simple-java-5-lines-on-time-and-o1-space-47k5 | \n public int maxPower(String s) {\n int res = 0, n = s.length();\n for(int i=0; i<n; i++){\n int j = i;\n\t\t\twhile(i+1 < n && s.c | ijaz20 | NORMAL | 2020-05-16T16:02:22.755542+00:00 | 2020-05-16T17:21:08.028776+00:00 | 319 | false | ```\n public int maxPower(String s) {\n int res = 0, n = s.length();\n for(int i=0; i<n; i++){\n int j = i;\n\t\t\twhile(i+1 < n && s.charAt(i) == s.charAt(i+1)) {i++;} \n res = Math.max(i-j+1, res);\n }\n return res;\n }\n``` | 5 | 12 | [] | 0 |
consecutive-characters | 💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 100 | easiestfaster-lesser-cpython3javacpython-fp8l | Intuition\n\n Describe your first thoughts on how to solve this problem. \n- JavaScript Code --> https://leetcode.com/problems/consecutive-characters/submission | Edwards310 | NORMAL | 2024-09-03T09:57:44.177482+00:00 | 2024-09-03T09:57:44.177509+00:00 | 486 | false | # Intuition\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n- ***JavaScript Code -->*** https://leetcode.com/problems/consecutive-characters/submissions/1377518875\n- ***C++... | 4 | 0 | ['String', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#'] | 0 |
consecutive-characters | C++ easy sol | c-easy-sol-by-richach10-xztw | \nclass Solution {\npublic:\n int maxPower(string s) {\n int maxi=1;\n int count=1;\n for(int i=1;i<s.size();i++){\n if(s[i]= | Richach10 | NORMAL | 2022-04-25T23:23:20.540775+00:00 | 2022-04-25T23:23:20.540803+00:00 | 273 | false | ```\nclass Solution {\npublic:\n int maxPower(string s) {\n int maxi=1;\n int count=1;\n for(int i=1;i<s.size();i++){\n if(s[i]==s[i-1]){\n count++;\n }\n else{\n count=1;\n }\n maxi=max(maxi,count); \n ... | 4 | 0 | ['C', 'C++'] | 0 |
consecutive-characters | JavaScript solution, faster than 97.78% | javascript-solution-faster-than-9778-by-ftid7 | \nvar maxPower = function(s) {\n let maxStr = 1;\n let accum = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === s[i + 1]) {\n | art_litvenko | NORMAL | 2021-12-13T10:34:55.840281+00:00 | 2021-12-14T18:42:18.953378+00:00 | 403 | false | ```\nvar maxPower = function(s) {\n let maxStr = 1;\n let accum = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === s[i + 1]) {\n maxStr += 1;\n } else {\n maxStr = 1;\n }\n if (maxStr > accum) {\n accum = maxStr;\n }\n }\n\n retu... | 4 | 0 | ['JavaScript'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.