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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reformat-the-string | Python Simple and Easy Explained Solution | python-simple-and-easy-explained-solutio-qrty | \nclass Solution:\n def reformat(self, s: str) -> str:\n # Create separate arrays for letters and digits:\n numbers = [c for c in s if c.isdigi | yehudisk | NORMAL | 2020-12-18T12:31:33.780294+00:00 | 2020-12-18T12:31:33.780333+00:00 | 455 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n # Create separate arrays for letters and digits:\n numbers = [c for c in s if c.isdigit()]\n letters = [c for c in s if c.isalpha()]\n\n # If there are too many digits or letters, return "":\n if abs(len(numbers) - len(let... | 6 | 0 | ['Python'] | 0 |
reformat-the-string | [Java] Simple O(n) solution | java-simple-on-solution-by-spirit_obi-bcbu | \npublic String reformat(String s) {\n\tList<Character> nums = new ArrayList<Character>();\n\tList<Character> alph = new ArrayList<Character>();\n\n\tfor (int i | spirit_obi | NORMAL | 2020-11-18T05:58:14.120493+00:00 | 2020-11-18T05:58:14.120539+00:00 | 805 | false | ```\npublic String reformat(String s) {\n\tList<Character> nums = new ArrayList<Character>();\n\tList<Character> alph = new ArrayList<Character>();\n\n\tfor (int i = 0; i < s.length(); i++) {\n\t\tif (Character.isDigit(s.charAt(i)))\n\t\t\tnums.add(s.charAt(i));\n\t\telse\n\t\t\talph.add(s.charAt(i));\n\t}\n\n\tif (Mat... | 6 | 0 | ['Java'] | 1 |
reformat-the-string | 5-line Easy Python solution with explanation | 5-line-easy-python-solution-with-explana-0cd0 | Explanation:\n\n1) d and c are list of digits and non-digits respectively.\n\n2) We return False if their (c and d) difference in length is greater than one \n\ | _xavier_ | NORMAL | 2020-04-19T04:07:44.170770+00:00 | 2020-04-22T04:05:41.781597+00:00 | 397 | false | **Explanation:**\n\n**1)** **d** and **c** are list of digits and non-digits respectively.\n\n**2)** We return False if their (c and d) difference in length is greater than one \n\n**3)** To see why to use **zip_longest** instead of **zip** see below example:\n\n\t\tzip([2, 1], [\'a\']) ----> ((... | 6 | 3 | [] | 5 |
reformat-the-string | [Python] simple, self explanatory solution, beats 100% | python-simple-self-explanatory-solution-bx4gf | ```class Solution(object):\n def reformat(self, s):\n """\n :type s: str\n :rtype: str\n """\n a=[]\n n=[]\n | manasswami | NORMAL | 2020-04-21T10:58:36.422758+00:00 | 2020-04-21T10:58:36.422795+00:00 | 370 | false | ```class Solution(object):\n def reformat(self, s):\n """\n :type s: str\n :rtype: str\n """\n a=[]\n n=[]\n s= list(s)\n length = len(s)\n for i in s:\n if i.isalpha():\n a.append(i)\n else:\n n.append... | 5 | 1 | [] | 0 |
reformat-the-string | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-pxjl | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\n#include<bits/stdc++.h>\nclass Solution {\npublic:\n string reformat(string s) \n {\n | shishirRsiam | NORMAL | 2024-05-22T05:20:43.212851+00:00 | 2024-05-22T05:20:43.212886+00:00 | 301 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\n#include<bits/stdc++.h>\nclass Solution {\npublic:\n string reformat(string s) \n {\n string digit, ch;\n for(char c:s)\n {\n if(isdigit(c)) digit += c;\n else ch += c;\n }\n int n = dig... | 4 | 0 | ['String', 'Simulation', 'C++'] | 4 |
reformat-the-string | JS very easy solution | js-very-easy-solution-by-kunkka1996-7q19 | \nconst regexNumber = /^[0-9]$/;\nvar reformat = function(s) {\n const letters = [];\n const numbers = [];\n\n for (let i = 0; i < s.length; i++) {\n | kunkka1996 | NORMAL | 2022-10-11T10:21:40.202908+00:00 | 2022-10-11T10:21:40.202945+00:00 | 718 | false | ```\nconst regexNumber = /^[0-9]$/;\nvar reformat = function(s) {\n const letters = [];\n const numbers = [];\n\n for (let i = 0; i < s.length; i++) {\n if(regexNumber.test(s[i])) {\n numbers.push(s[i]);\n } else {\n letters.push(s[i]);\n }\n }\n \n if (Math.... | 4 | 0 | ['JavaScript'] | 0 |
reformat-the-string | Java easiest to understand | java-easiest-to-understand-by-yelhsabana-kvpi | i separate my helper function from the main to make the logic simpler and clearer\n\nclass Solution {\n public String reformat(String s) {\n List<Char | yelhsabananah | NORMAL | 2020-04-20T03:13:21.589425+00:00 | 2020-04-20T03:13:21.589469+00:00 | 565 | false | i separate my helper function from the main to make the logic simpler and clearer\n```\nclass Solution {\n public String reformat(String s) {\n List<Character> str = new ArrayList<>(), nums = new ArrayList<>();\n for (char c : s.toCharArray()) {\n if (Character.isDigit(c)) {\n ... | 4 | 1 | [] | 0 |
reformat-the-string | C++ Simplest intuitive solution | c-simplest-intuitive-solution-by-hammerh-9kro | ```\nclass Solution {\npublic:\n string reformat(string s) {\n string str1, str2; // str1 will store letters and str2 will store digits\n \n | hammerhead09 | NORMAL | 2020-04-19T06:52:27.622485+00:00 | 2020-04-19T06:59:06.393240+00:00 | 500 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n string str1, str2; // str1 will store letters and str2 will store digits\n \n for (auto &ch : s)\n if (!isdigit(ch))\n str1 += ch;\n else\n str2 += ch;\n \n int diff =... | 4 | 3 | [] | 1 |
reformat-the-string | Javascript segregate alphabets and numbers Solution | javascript-segregate-alphabets-and-numbe-abjt | \nvar reformat = function(s) {\n var nums = [];\n var alph = [];\n var res = [];\n for(var i=0;i<s.length;i++){\n if(s[i]>=\'0\' && s[i]<=\'9 | seriously_ridhi | NORMAL | 2020-04-19T05:13:02.956609+00:00 | 2020-04-19T05:13:30.829268+00:00 | 551 | false | ```\nvar reformat = function(s) {\n var nums = [];\n var alph = [];\n var res = [];\n for(var i=0;i<s.length;i++){\n if(s[i]>=\'0\' && s[i]<=\'9\'){\n nums.push(s[i]);\n }else{\n alph.push(s[i]);\n }\n }\n if(Math.abs(nums.length-alph.length)>1){\n ret... | 4 | 0 | ['JavaScript'] | 1 |
reformat-the-string | JavaScript Beginner-level code is very simple to understand | javascript-beginner-level-code-is-very-s-y6kl | 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 | althaff | NORMAL | 2024-08-10T20:29:38.975751+00:00 | 2024-08-10T20:29:38.975778+00:00 | 148 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 0 | ['JavaScript'] | 1 |
reformat-the-string | 100% FAST C++ BEST SOLUTION 🤩 | 100-fast-c-best-solution-by-harshitsachd-ru3v | 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\n\n# Complexity\n- T | harshitsachdeva1219 | NORMAL | 2023-04-08T07:24:34.869171+00:00 | 2023-06-25T17:03:03.352105+00:00 | 546 | 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\n\n# Complexity\n- Time complexity: O(size of string)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(size of string)\n<!-- Add your... | 3 | 0 | ['String', 'C++'] | 1 |
reformat-the-string | Go solution that beats 100% | go-solution-that-beats-100-by-tuanbieber-2bfa | \nfunc reformat(s string) string {\n\talphabet, alphabetCount := make([]byte, 26), 0\n\tdigit, digitCount := make([]byte, 10), 0\n\tstr := make([]byte, len(s))\ | tuanbieber | NORMAL | 2022-08-22T09:11:08.268160+00:00 | 2022-08-22T09:11:08.268193+00:00 | 324 | false | ```\nfunc reformat(s string) string {\n\talphabet, alphabetCount := make([]byte, 26), 0\n\tdigit, digitCount := make([]byte, 10), 0\n\tstr := make([]byte, len(s))\n\n\tfor i := 0; i < len(s); i++ {\n\t\tif s[i] >= \'a\' && s[i] <= \'z\' {\n\t\t\talphabet[s[i]-\'a\']++\n\t\t\talphabetCount++\n\t\t} else {\n\t\t\tdigit[s... | 3 | 0 | ['Go'] | 1 |
reformat-the-string | Using itertools.zip_longest (Python 3) | using-itertoolszip_longest-python-3-by-e-muce | Here\'s an approach similar to other ones, but using itertools.zip_longest instead of zip:\n\nclass Solution:\n def reformat(self, s: str) -> str:\n n | emwalker | NORMAL | 2021-11-28T22:41:31.933819+00:00 | 2021-11-28T22:41:31.933852+00:00 | 119 | false | Here\'s an approach similar to other ones, but using `itertools.zip_longest` instead of `zip`:\n```\nclass Solution:\n def reformat(self, s: str) -> str:\n nums = [c for c in s if c.isnumeric()]\n alph = [c for c in s if c.isalpha()]\n \n if abs(len(nums) - len(alph)) > 1:\n ... | 3 | 0 | ['Python3'] | 0 |
reformat-the-string | Simple 2 array JavaScript solution | simple-2-array-javascript-solution-by-at-qaqt | \nvar reformat = function(s) {\n const strArr = [];\n\tconst numArr = [];\n let str = \'\';\n \n for(let i = 0; i < s.length; i++) {\n if(isN | AT34007 | NORMAL | 2021-09-10T07:41:35.978204+00:00 | 2021-09-10T07:41:35.978249+00:00 | 179 | false | ```\nvar reformat = function(s) {\n const strArr = [];\n\tconst numArr = [];\n let str = \'\';\n \n for(let i = 0; i < s.length; i++) {\n if(isNaN(s[i])) {\n strArr.push(s[i]);\n }\n else {\n numArr.push(s[i]);\n }\n }\n const numLen = numArr.length;\n... | 3 | 0 | ['Array', 'JavaScript'] | 0 |
reformat-the-string | [Java] StringBuilder Solution | java-stringbuilder-solution-by-vinsinin-81pf | \nclass Solution {\n public String reformat(String s) {\n // StringBuilder for maintaining the characters\n\t\tStringBuilder sb = new StringBuilder(); | vinsinin | NORMAL | 2021-02-21T21:32:08.901162+00:00 | 2021-02-21T21:32:08.901204+00:00 | 735 | false | ```\nclass Solution {\n public String reformat(String s) {\n // StringBuilder for maintaining the characters\n\t\tStringBuilder sb = new StringBuilder();\n StringBuilder alpha = new StringBuilder();\n StringBuilder digit = new StringBuilder();\n \n\t\t// separate digits and alpha numerics... | 3 | 0 | ['String', 'Java'] | 1 |
reformat-the-string | Python, filter based approach. FAST and simple. | python-filter-based-approach-fast-and-si-5qwn | \nclass Solution:\n def reformat(self, s: str) -> str:\n a1 = list(filter(str.isalpha, s))\n a2 = list(filter(str.isdigit, s))\n\n if ab | blue_sky5 | NORMAL | 2020-10-25T23:28:06.814114+00:00 | 2020-10-25T23:28:06.814157+00:00 | 506 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n a1 = list(filter(str.isalpha, s))\n a2 = list(filter(str.isdigit, s))\n\n if abs(len(a1) - len(a2)) > 1:\n return ""\n \n if len(a1) < len(a2): # ensure len(a1) >= len(a2)\n a1, a2 = a2, a1\n ... | 3 | 0 | ['Python', 'Python3'] | 1 |
reformat-the-string | Accepted Java - O(N) time and space | accepted-java-on-time-and-space-by-pd93-nvvs | \nclass Solution {\n public String reformat(String s) {\n \n // 1.) Separate chars and letters\n \n StringBuffer chars = new Stri | pd93 | NORMAL | 2020-04-19T04:24:36.462906+00:00 | 2020-04-20T01:37:28.323403+00:00 | 787 | false | ```\nclass Solution {\n public String reformat(String s) {\n \n // 1.) Separate chars and letters\n \n StringBuffer chars = new StringBuffer();\n StringBuffer letters = new StringBuffer(); \n for(Character c:s.toCharArray()){\n if(Character.isDigit(c)){\n ... | 3 | 0 | ['Java'] | 2 |
reformat-the-string | Java | Clean Concise | O(N) time and O(N) space | java-clean-concise-on-time-and-on-space-cdtb0 | ```\n public String reformat(String s) {\n List digits = new ArrayList<>();\n List letters = new ArrayList<>();\n StringBuilder res = ne | ping_pong | NORMAL | 2020-04-19T04:04:44.143334+00:00 | 2020-04-19T04:04:44.143364+00:00 | 275 | false | ```\n public String reformat(String s) {\n List<Character> digits = new ArrayList<>();\n List<Character> letters = new ArrayList<>();\n StringBuilder res = new StringBuilder();\n char[] sChars = s.toCharArray();\n int n = sChars.length;\n for (char sChar : sChars) {\n ... | 3 | 2 | [] | 0 |
reformat-the-string | BEST solution using STACK ..Easy to unserstand with comments | best-solution-using-stack-easy-to-unsers-3ecr | 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 | ankurtiwari120196 | NORMAL | 2023-12-23T05:01:10.136285+00:00 | 2023-12-23T05:01:10.136304+00:00 | 383 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Java'] | 0 |
reformat-the-string | 100%beat,best approach to do this question in c++!! | 100beatbest-approach-to-do-this-question-il9v | 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 | Ashwin_Bharti | NORMAL | 2023-02-17T16:00:38.094707+00:00 | 2023-02-17T16:00:38.094752+00:00 | 698 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['C++'] | 1 |
reformat-the-string | Java || Two - Pointer | java-two-pointer-by-code_sanket-wo2d | \nclass Solution {\n public String reformat(String s) {\n StringBuilder alpha = new StringBuilder();\n StringBuilder digit = new StringBuilder( | code_sanket | NORMAL | 2023-01-11T07:58:24.536132+00:00 | 2023-01-11T07:58:24.536164+00:00 | 793 | false | ```\nclass Solution {\n public String reformat(String s) {\n StringBuilder alpha = new StringBuilder();\n StringBuilder digit = new StringBuilder();\n \n \n for(int i = 0 ; i < s.length() ; i++){\n char ch = s.charAt(i);\n if(ch >= \'0\' && ch <= \'9\'){\n ... | 2 | 0 | ['Two Pointers', 'String', 'Java'] | 0 |
reformat-the-string | C++ O(N) Time | O(1) space **Excluding answer | Two Pass | Counts and alternative Indexes | c-on-time-o1-space-excluding-answer-two-rs8ay | ```\nclass Solution {\npublic:\n \n string reformat(string s) {\n int digits{};\n int chars{};\n \n // count digits and spaces | cg1lc | NORMAL | 2022-08-13T06:24:16.445507+00:00 | 2022-08-13T06:25:50.560081+00:00 | 183 | false | ```\nclass Solution {\npublic:\n \n string reformat(string s) {\n int digits{};\n int chars{};\n \n // count digits and spaces\n for (auto ch : s)\n {\n if (ch >= \'a\' && ch <= \'z\') ++chars;\n else ++digits;\n }\n \n // If cou... | 2 | 0 | [] | 0 |
reformat-the-string | [Javascript] ALTERNATING Reformat using STACK | javascript-alternating-reformat-using-st-r2g3 | Intuition\n\nCollect all letter and digit first and count their number.\n\nIf diff(letter.len, digit.len)>1, just return "".\nOtherwise, we get 1 from BOTH arra | lynn19950915 | NORMAL | 2022-06-17T10:53:51.352412+00:00 | 2023-05-27T04:47:55.347262+00:00 | 256 | false | **Intuition**\n\nCollect all `letter` and `digit` first and count their number.\n\nIf `diff`(letter.len, digit.len)>1, just return `""`.\nOtherwise, we get 1 from BOTH array, and **always add letter first, then digit**.\n\n```\nL-D-L-D-...-L-D\n```\n\n> if there\'s a `letter` left, add it in the **END** -> `L-D-L-D-...... | 2 | 0 | ['Stack', 'JavaScript'] | 0 |
reformat-the-string | Java O(1) space , O(N) time | java-o1-space-on-time-by-mesonny-9b9d | \n//2022/1/13 \u9019\u4E00\u984C\u4E0D\u7BA1\u600E\u6A23\u4E00\u5B9A\u8981\u5148\u5F97\u5230letters \u8DDF digits\u7684\u9577\u5EA6\n\nclass Solution {\n pub | mesonny | NORMAL | 2022-01-12T16:18:56.421295+00:00 | 2022-01-12T16:18:56.421330+00:00 | 147 | false | ```\n//2022/1/13 \u9019\u4E00\u984C\u4E0D\u7BA1\u600E\u6A23\u4E00\u5B9A\u8981\u5148\u5F97\u5230letters \u8DDF digits\u7684\u9577\u5EA6\n\nclass Solution {\n public String reformat(String s) {\n \n //prepare answer buffer\n int k = 0;\n char[] ans = new char[s.length()];\n \n ... | 2 | 0 | [] | 1 |
reformat-the-string | Java solution | java-solution-by-humblef00l-jv1e | \nclass Solution {\n public String reformat(String s) {\n List<Character> digit = new ArrayList<>();\n List<Character> letter = new ArrayList<> | HUMBLEF00L | NORMAL | 2022-01-05T08:47:00.104041+00:00 | 2022-01-05T08:47:00.104093+00:00 | 68 | false | ```\nclass Solution {\n public String reformat(String s) {\n List<Character> digit = new ArrayList<>();\n List<Character> letter = new ArrayList<>();\n for(int i =0;i<s.length();i++)\n {\n char now = s.charAt(i);\n if(Character.isLetter(now)){\n letter... | 2 | 0 | [] | 0 |
reformat-the-string | Simple java solution | simple-java-solution-by-siddhant_1602-jgew | class Solution {\n\n public String reformat(String s) {\n int i,c=0,m=0;\n String w="",d="";\n for(i=0;i=\'a\'&&s.charAt(i)<=\'z\')\n | Siddhant_1602 | NORMAL | 2021-08-01T16:44:25.698036+00:00 | 2022-03-08T06:23:03.503558+00:00 | 103 | false | class Solution {\n\n public String reformat(String s) {\n int i,c=0,m=0;\n String w="",d="";\n for(i=0;i<s.length();i++)\n {\n if(s.charAt(i)>=\'a\'&&s.charAt(i)<=\'z\')\n {\n c++;\n w=w+s.charAt(i);\n }\n else if(s... | 2 | 0 | [] | 0 |
reformat-the-string | Rust solution | rust-solution-by-bigmih-hyge | \nimpl Solution {\n pub fn reformat(s: String) -> String {\n let num_digits = s.chars().filter(|c| c.is_ascii_digit()).count() as i32;\n let nu | BigMih | NORMAL | 2021-07-09T16:43:07.266254+00:00 | 2021-07-09T16:43:07.266308+00:00 | 85 | false | ```\nimpl Solution {\n pub fn reformat(s: String) -> String {\n let num_digits = s.chars().filter(|c| c.is_ascii_digit()).count() as i32;\n let num_chars = s.len() as i32 - num_digits;\n\n if (num_digits - num_chars).abs() > 1 {\n return "".to_owned();\n }\n\n let mut re... | 2 | 0 | ['Rust'] | 0 |
reformat-the-string | simple and basic | simple-and-basic-by-hrushee-kewb | \n\nclass Solution {\npublic:\n string reformat(string s) {\n string n="";\n string a="";\n for(auto i:s)\n {\n if(isd | Hrushee | NORMAL | 2021-06-14T18:37:14.361498+00:00 | 2021-06-14T18:37:14.361521+00:00 | 408 | false | \n```\nclass Solution {\npublic:\n string reformat(string s) {\n string n="";\n string a="";\n for(auto i:s)\n {\n if(isdigit(i))\n {\n n+=i;\n }\n else\n {\n a+=i;\n }\n }\n int ... | 2 | 0 | ['C', 'C++'] | 0 |
reformat-the-string | [Java] Simple and Easy - EASY PEASY - O(N) - No Comments Needed | java-simple-and-easy-easy-peasy-on-no-co-s37x | \n\uD83D\uDC46\uD83D\uDC46UPVOTE IF YOU FIND THIS USEFUL\uD83D\uDC46\uD83D\uDC46\n\n\n\nclass Solution {\n public String reformat(String s) {\n int c | pulkitswami7 | NORMAL | 2020-09-14T05:32:11.481541+00:00 | 2020-09-14T05:32:11.481612+00:00 | 249 | false | <hr>\n\uD83D\uDC46\uD83D\uDC46UPVOTE IF YOU FIND THIS USEFUL\uD83D\uDC46\uD83D\uDC46\n<hr>\n\n```\nclass Solution {\n public String reformat(String s) {\n int c = 0, d = 0;\n for(char ch: s.toCharArray()){\n if(Character.isLetter(ch))\n c++;\n else\n ... | 2 | 0 | [] | 0 |
reformat-the-string | Java 3ms StringBuilder | java-3ms-stringbuilder-by-sydneylin12-q0qm | \nclass Solution {\n public String reformat(String s) {\n if(s.length() == 1) return s;\n \n StringBuilder letters = new StringBuilder() | squidimenz | NORMAL | 2020-09-12T01:56:19.109863+00:00 | 2020-09-12T01:56:19.109925+00:00 | 201 | false | ```\nclass Solution {\n public String reformat(String s) {\n if(s.length() == 1) return s;\n \n StringBuilder letters = new StringBuilder();\n StringBuilder digits = new StringBuilder();\n \n for(int i = 0; i < s.length(); i++){\n if(Character.isDigit(s.charAt(i))... | 2 | 0 | [] | 0 |
reformat-the-string | [PYTHON] Simple and Easy to understand | python-simple-and-easy-to-understand-by-gstff | \nclass Solution:\n def reformat(self, s: str) -> str:\n a=[]\n b=[]\n ans=\'\'\n for i in s:\n if i.isalpha():\n | het952 | NORMAL | 2020-06-24T05:31:09.438232+00:00 | 2020-06-24T05:31:09.438278+00:00 | 90 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n a=[]\n b=[]\n ans=\'\'\n for i in s:\n if i.isalpha():\n a.append(i)\n else:\n b.append(i)\n if abs(len(a)-len(b))<=1:\n while a and b:\n ans+=a... | 2 | 0 | [] | 0 |
reformat-the-string | JavaScript easy understand | javascript-easy-understand-by-liangcode-acph | JavaScript Solution\n\n let letters = [];\n let digits = [];\n let res = \'\';\n \n for (let char of s) {\n if (\'a\' <= char && char <= \ | liangcode | NORMAL | 2020-04-30T20:55:26.494516+00:00 | 2020-04-30T20:56:35.344698+00:00 | 289 | false | JavaScript Solution\n\n let letters = [];\n let digits = [];\n let res = \'\';\n \n for (let char of s) {\n if (\'a\' <= char && char <= \'z\') {\n letters.push(char);\n } else {\n digits.push(char);\n }\n }\n let difference = letters.length - digits.len... | 2 | 0 | ['JavaScript'] | 1 |
reformat-the-string | Easy to understand code | easy-to-understand-code-by-gh05t-8ubp | \nif(s == "")\n return "";\n\t\nint countW(0), countD(0);\nstring w, d;\nfor(const auto &c: s) {\n if(isdigit(c)) {\n countD++;\n d += c;\n | gh05t | NORMAL | 2020-04-20T00:46:21.155790+00:00 | 2020-04-20T03:09:30.125698+00:00 | 265 | false | ```\nif(s == "")\n return "";\n\t\nint countW(0), countD(0);\nstring w, d;\nfor(const auto &c: s) {\n if(isdigit(c)) {\n countD++;\n d += c;\n } else {\n countW++;\n w += c;\n }\n}\n\nif(abs(countW - countD) != 0 && abs(countW - countD) != 1)\n return "";\n\t\nstring ans(count... | 2 | 0 | ['C'] | 1 |
reformat-the-string | Java solution with comments | java-solution-with-comments-by-dhiren_72-bojk | Hope my solution helps\n\nclass Solution {\n public String reformat(String s) {\n ArrayList<Character> c = new ArrayList<>(); // to store character | dhiren_720 | NORMAL | 2020-04-19T05:32:06.671705+00:00 | 2020-04-19T05:32:06.671775+00:00 | 186 | false | Hope my solution helps\n```\nclass Solution {\n public String reformat(String s) {\n ArrayList<Character> c = new ArrayList<>(); // to store character like a,b,c\n ArrayList<Character> n = new ArrayList<>(); // to store digits like 1,2,3\n for(int i=0;i<s.length();i++){\n char c1 =... | 2 | 1 | [] | 0 |
reformat-the-string | Python Solution using zip_longest() | python-solution-using-zip_longest-by-cpp-vu8q | \nfrom itertools import zip_longest\n\nclass Solution: \n def reformat(self, s: str) -> str:\n if len(s) == 1:\n return s\n\t\t\t\n\t\t# I | cppygod | NORMAL | 2020-04-19T04:11:32.015238+00:00 | 2020-04-19T04:17:15.550917+00:00 | 254 | false | ```\nfrom itertools import zip_longest\n\nclass Solution: \n def reformat(self, s: str) -> str:\n if len(s) == 1:\n return s\n\t\t\t\n\t\t# If the input string contains only digits (or) only letters\n if s.isalpha() or s.isdigit():\n return ""\n \n\t\t# Getting the numbers... | 2 | 1 | ['Python', 'Python3'] | 0 |
reformat-the-string | C++ simple O(n) solution | c-simple-on-solution-by-sanyamg99-xlb7 | \nclass Solution {\npublic:\n string reformat(string s) {\n string a="",b="";\n for(int i=0;i<s.length();i++){\n if(isdigit(s[i])) b | sanyamg99 | NORMAL | 2020-04-19T04:03:38.109687+00:00 | 2020-04-19T04:03:38.109740+00:00 | 173 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n string a="",b="";\n for(int i=0;i<s.length();i++){\n if(isdigit(s[i])) b+=s[i];\n else a+=s[i];\n }\n if(a=="" && b.length()==1) return b;\n else if(b=="" && a.length()==1) return a;\n else ... | 2 | 1 | [] | 0 |
reformat-the-string | [C++] Interpolating two arrays | c-interpolating-two-arrays-by-zhanghuime-d54a | Given an array containing lowercase letters and digits, return a new array interpolating letters and digits.\n\n# Explanation\n\nThe difference between the numb | zhanghuimeng | NORMAL | 2020-04-19T04:01:22.806967+00:00 | 2020-04-19T04:01:22.807024+00:00 | 627 | false | Given an array containing lowercase letters and digits, return a new array interpolating letters and digits.\n\n# Explanation\n\nThe difference between the number of letters and digits must be <= 1. Just interpolate the one with bigger size first.\n\nThe time complexity is O(n).\n\n# C++ Solution\n\n```cpp\nclass Solut... | 2 | 1 | [] | 0 |
reformat-the-string | Solution Palindrome do Lucas Marcao - slow. | solution-palindrome-do-lucas-marcao-slow-9txo | IntuitionMinha primeira ideia para resolver esse problema foi garantir que a string resultante alternasse entre letras e números. Eu sabia que, para isso, seria | marcaozitos | NORMAL | 2025-03-28T16:14:20.042359+00:00 | 2025-03-28T16:14:20.042359+00:00 | 33 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Minha primeira ideia para resolver esse problema foi garantir que a string resultante alternasse entre letras e números. Eu sabia que, para isso, seria necessário contar a quantidade de letras e números na string de entrada e verificar se a... | 1 | 0 | ['Array', 'Math', 'String', 'C++'] | 1 |
reformat-the-string | Code is lengthy but logic is very simple | please upvote | code-is-lengthy-but-logic-is-very-simple-5rh7 | \n\n# Code\njava []\nclass Solution {\n public String reformat(String s) {\n StringBuilder l=new StringBuilder();\n StringBuilder d=new StringB | Lil_kidZ | NORMAL | 2024-09-19T23:34:14.466731+00:00 | 2024-09-19T23:34:14.466759+00:00 | 242 | false | \n\n# Code\n```java []\nclass Solution {\n public String reformat(String s) {\n StringBuilder l=new StringBuilder();\n StringBuilder d=new StringBuilder();\n StringBuilder ans=new StringBuilder();\n for(int i=0;i<s.length();i++){\n if(Character.isLetter(s.charAt(i))){\n ... | 1 | 0 | ['Java'] | 0 |
reformat-the-string | bahut saare cases handle krne pade need to optimize it a lot hum bhi kr lenge :D | bahut-saare-cases-handle-krne-pade-need-l9qwa | 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 | yesyesem | NORMAL | 2024-09-09T18:42:36.303066+00:00 | 2024-09-09T18:42:36.303100+00:00 | 69 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
reformat-the-string | 45 MS | IT IS SIMPLE FOR YOU | 45-ms-it-is-simple-for-you-by-justchis10-6ggc | \n\n# CODE\n\nclass Solution:\n def reformat(self, s: str) -> str:\n ls = list(s)\n digits = list(filter(lambda x : x.isdigit(), list(s)))\n | JustChis100 | NORMAL | 2024-03-29T16:50:00.165664+00:00 | 2024-03-29T16:50:00.165694+00:00 | 208 | false | \n\n# CODE\n```\nclass Solution:\n def reformat(self, s: str) -> str:\n ls = list(s)\n digits = list(filter(lambda x : x.isdigit(), list(s)))\n letters = list(filter(lambda x : not x.isdigit(), list(s)))\n cd = len(digits)\n cl = len(letters)\n res = ""\n if abs(cd - ... | 1 | 0 | ['String', 'Python', 'Python3'] | 1 |
reformat-the-string | Easy method for beginners O(n) | easy-method-for-beginners-on-by-arun_bal-7ia6 | 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 | arun_balakrishnan | NORMAL | 2024-03-20T17:21:21.668499+00:00 | 2024-03-20T17:21:21.668531+00:00 | 353 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Python3'] | 0 |
reformat-the-string | Easy 3ms java solution, beats 94.21% | easy-3ms-java-solution-beats-9421-by-ari-r06j | 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 | arijeet7 | NORMAL | 2024-02-26T15:10:11.876841+00:00 | 2024-02-26T15:10:11.876878+00:00 | 383 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 1 |
reformat-the-string | [ANSI C] Brute force | ansi-c-brute-force-by-pbelskiy-s9bi | c\n#define MAX_CHARS 500\n\nchar *reformat(char *s)\n{\n int l = 0, n = 0;\n\n char *letters = malloc(MAX_CHARS);\n char *numbers = malloc(MAX_CHARS);\ | pbelskiy | NORMAL | 2023-09-12T14:00:30.769503+00:00 | 2023-09-12T14:00:30.769526+00:00 | 65 | false | ```c\n#define MAX_CHARS 500\n\nchar *reformat(char *s)\n{\n int l = 0, n = 0;\n\n char *letters = malloc(MAX_CHARS);\n char *numbers = malloc(MAX_CHARS);\n\n for (int i = 0 ; i < strlen(s) ; i++) {\n if (s[i] >= \'a\') {\n letters[l++] = s[i];\n } else {\n numbers[n++] = ... | 1 | 0 | ['C'] | 0 |
reformat-the-string | C++ easy/simple Solution || Best Sol || easy to Understand || simple Approach | c-easysimple-solution-best-sol-easy-to-u-u57n | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n## c++ simple Solution | sanjiv0286 | NORMAL | 2023-07-01T06:53:24.751288+00:00 | 2023-07-01T06:53:24.751312+00:00 | 28 | 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## c++ simple Solution easy to understand\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add y... | 1 | 0 | ['C++'] | 1 |
reformat-the-string | [Python3] - One-Pass - No Space other than Solution | python3-one-pass-no-space-other-than-sol-7mg9 | Intuition\n Describe your first thoughts on how to solve this problem. \nWe make an array which is one larger than our input string and put digits at every even | Lucew | NORMAL | 2022-10-26T21:00:25.774723+00:00 | 2022-10-26T21:00:25.774766+00:00 | 86 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe make an array which is one larger than our input string and put digits at every even and characters at every odd position.\n\nWhile doing that we increase pointers for both of those. Once these pointers are out of scope, we have too ma... | 1 | 0 | ['Python3'] | 0 |
reformat-the-string | C++ | STL | O(N) | SPACE(N) | c-stl-on-spacen-by-nmashtalirov-0ojh | Algorithm:\n\n1. Divide the source string into letters and numbers using the standard std::stable_partition function.\n\n2. Check that the number of letters and | nmashtalirov | NORMAL | 2022-09-22T15:11:57.482017+00:00 | 2022-09-22T15:11:57.482066+00:00 | 74 | false | **Algorithm:**\n\n1. Divide the source string into letters and numbers using the standard std::stable_partition function.\n\n2. Check that the number of letters and numbers differs by no more than 1 modulo, otherwise return an empty string.\n\n3. If there are more letters the numbers, add the first letter to the format... | 1 | 0 | ['C', 'C++'] | 0 |
reformat-the-string | C# | c-by-neildeng0705-h1vf | \npublic class Solution {\n public string Reformat(string s) \n { \n char[] digits = s.ToCharArray().Where(x => Char.IsDigit(x)).ToArray();\n | neildeng0705 | NORMAL | 2022-08-13T15:06:43.831106+00:00 | 2022-08-13T15:06:43.831149+00:00 | 130 | false | ```\npublic class Solution {\n public string Reformat(string s) \n { \n char[] digits = s.ToCharArray().Where(x => Char.IsDigit(x)).ToArray();\n char[] chars = s.ToCharArray().Where(x => !Char.IsDigit(x)).ToArray();\n\n if (Math.Abs(digits.Length-chars.Length) > 1)\n {\n re... | 1 | 0 | [] | 0 |
reformat-the-string | Java O(n) Runtime better than 97% Space better than 96% | java-on-runtime-better-than-97-space-bet-l1wf | \nclass Solution {\n public String reformat(String s) {\n int letters = 0, numbers = 0;\n for(char c : s.toCharArray()){\n if(Charac | anonymousLCer | NORMAL | 2022-07-22T17:36:51.364756+00:00 | 2022-07-22T17:36:51.364791+00:00 | 208 | false | ```\nclass Solution {\n public String reformat(String s) {\n int letters = 0, numbers = 0;\n for(char c : s.toCharArray()){\n if(Character.isDigit(c)) numbers++;\n else letters++;\n }\n \n if(Math.abs(letters - numbers) > 1) return "";\n return letters ... | 1 | 0 | [] | 0 |
reformat-the-string | Python | Easy Solution | python-easy-solution-by-aryonbe-4rld | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n alphabets = []\n numerics = []\n for c in s:\n if c.isnumeric():\ | aryonbe | NORMAL | 2022-07-17T22:20:22.989420+00:00 | 2022-07-17T22:20:22.989451+00:00 | 325 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n alphabets = []\n numerics = []\n for c in s:\n if c.isnumeric():\n numerics.append(c)\n else:\n alphabets.append(c)\n if abs(len(alphabets) - len(numerics)) > 1: return ""\n ... | 1 | 0 | ['Python'] | 0 |
reformat-the-string | c++ | easy | basic | c-easy-basic-by-srv-er-en9v | \nclass Solution {\npublic:\n string reformat(string s) {\n string dg,al;\n for(auto&i:s)isdigit(i)?dg+=i:al+=i;\n if(abs((int)size(dg)- | srv-er | NORMAL | 2022-07-05T01:14:43.430017+00:00 | 2022-07-05T01:14:43.430062+00:00 | 337 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n string dg,al;\n for(auto&i:s)isdigit(i)?dg+=i:al+=i;\n if(abs((int)size(dg)-(int)size(al))>1) return "";\n int i=0,j=0,k=0;\n string ans(size(s),\' \');\n bool cdg=size(dg)>size(al);\n while(k<size(s)){\n ... | 1 | 0 | ['C'] | 0 |
reformat-the-string | O(n) time, O(n) space, concise, stack | on-time-on-space-concise-stack-by-yayaro-9n6w | \npublic class Solution {\n public string Reformat(string s) {\n var digits = new Stack<char>(s.Where(c => \'0\' <= c && c <= \'9\'));\n var le | yayarokya | NORMAL | 2022-04-21T12:44:47.084153+00:00 | 2022-04-21T12:50:51.154193+00:00 | 64 | false | ```\npublic class Solution {\n public string Reformat(string s) {\n var digits = new Stack<char>(s.Where(c => \'0\' <= c && c <= \'9\'));\n var letters = new Stack<char>(s.Where(c => c < \'0\' || \'9\' < c));\n if(1 < Math.Abs(digits.Count - letters.Count)) {\n return "";\n }\n... | 1 | 0 | ['Stack'] | 0 |
reformat-the-string | Python3 Solution | python3-solution-by-hgalytoby-6lzh | python\nclass Solution:\n def reformat(self, s: str) -> str:\n nums, chars = [], []\n [(chars, nums)[char.isdigit()].append(str(char)) for char | hgalytoby | NORMAL | 2022-03-19T14:27:43.739450+00:00 | 2022-03-19T14:40:03.113228+00:00 | 134 | false | ```python\nclass Solution:\n def reformat(self, s: str) -> str:\n nums, chars = [], []\n [(chars, nums)[char.isdigit()].append(str(char)) for char in s]\n nums_len, chars_len = len(nums), len(chars)\n if 2 > nums_len - chars_len > -2:\n a, b = ((chars, nums), (nums, chars))[num... | 1 | 0 | ['Python3'] | 0 |
reformat-the-string | Python solution with no extra space | python-solution-with-no-extra-space-by-l-dt8z | \nclass Solution:\n def reformat(self, s: str) -> str:\n count_alpha = 0\n count_digit = 0\n \n for i in s:\n \n | lazarus29 | NORMAL | 2022-03-02T21:03:43.658570+00:00 | 2022-03-02T21:03:43.658601+00:00 | 74 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n count_alpha = 0\n count_digit = 0\n \n for i in s:\n \n if i.isalpha():\n count_alpha += 1\n else:\n count_digit += 1\n \n if abs(count_alpha - count_di... | 1 | 0 | [] | 0 |
reformat-the-string | C++ | CPP | 100% FASTER | 80% SPACE | SIMPLE SOLUTION | c-cpp-100-faster-80-space-simple-solutio-muci | \nclass Solution {\npublic:\n string reformat(string s) {\n int n = s.size();\n string ans,digits,chars;\n for(int i = 0;i<n;i++){\n | UnknownOffline | NORMAL | 2022-02-11T06:10:52.732075+00:00 | 2022-02-11T06:10:52.732100+00:00 | 251 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n int n = s.size();\n string ans,digits,chars;\n for(int i = 0;i<n;i++){\n if(s[i] >= \'0\' && s[i] <= \'9\') digits += s[i];\n else chars += s[i];\n }\n int i = 0, j = 0;\n int diff = digits.... | 1 | 0 | ['C', 'C++'] | 0 |
reformat-the-string | Simple C++ Solution | simple-c-solution-by-trishit-pal-4nhi | \tstring reformat(string s) {\n vector s1,s2;\n for(int i=0;i1)\n return "";\n int i=0,j=0;\n string ans="";\n if( | trishit-pal | NORMAL | 2022-01-05T09:04:04.963893+00:00 | 2022-01-05T09:04:04.963932+00:00 | 214 | false | \tstring reformat(string s) {\n vector<char> s1,s2;\n for(int i=0;i<s.size();i++)\n {\n if(isalpha(s[i]))\n s1.push_back(s[i]);\n else\n s2.push_back(s[i]);\n }\n int n=s1.size(), m=s2.size();\n if(abs(n-m)>1)\n ret... | 1 | 0 | ['C', 'C++'] | 0 |
reformat-the-string | Easy Python Solution | easy-python-solution-by-lizz04-s8zb | ``` \n\tdef reformat(self, s: str) -> str:\n digit=[]\n char=[]\n for i in s:\n if i>=\'0\' and i<=\'9\':\n di | Lizz04 | NORMAL | 2021-12-26T09:15:23.161671+00:00 | 2021-12-26T09:15:23.161713+00:00 | 137 | false | ``` \n\tdef reformat(self, s: str) -> str:\n digit=[]\n char=[]\n for i in s:\n if i>=\'0\' and i<=\'9\':\n digit.append(i)\n else:\n char.append(i)\n n1=len(digit)\n n2=len(char)\n if abs(n1-n2)>1:\n return \'\'... | 1 | 0 | ['Python'] | 0 |
reformat-the-string | Rust | rust-by-mee_ci-2w00 | \n\nstruct Solution{}\nimpl Solution {\n pub fn reformat(s: String) -> String {\n let mut sr = String::from("");\n let mut vsr:Vec<char> = vec! | Mee_CI | NORMAL | 2021-12-07T04:51:29.826846+00:00 | 2021-12-07T04:51:29.826881+00:00 | 37 | false | ```\n\nstruct Solution{}\nimpl Solution {\n pub fn reformat(s: String) -> String {\n let mut sr = String::from("");\n let mut vsr:Vec<char> = vec![];\n let mut vnum : Vec<char> = vec![];\n for i in s.chars(){\n if i.is_digit(10){\n vnum.push(i);\n }els... | 1 | 0 | ['Rust'] | 0 |
reformat-the-string | C++ | Faster than 100% || well commented | c-faster-than-100-well-commented-by-real-epxw | To start I read the problem and wrote down some thoughts on how i would solve and what i needed to look for. the order of the alg was a little different than th | realphilycheese | NORMAL | 2021-11-29T06:01:22.233093+00:00 | 2021-11-29T06:05:08.076871+00:00 | 82 | false | To start I read the problem and wrote down some thoughts on how i would solve and what i needed to look for. the order of the alg was a little different than the notes because they were just notes:\n\nCheck number of chars\nCheck number of digits\n\tpush chars to a vector and digits to a vector\n\nIf chars > digits ? S... | 1 | 0 | [] | 1 |
reformat-the-string | python if else tree | python-if-else-tree-by-vigneswar_a-cd0o | \nclass Solution:\n def reformat(self, s: str) -> str:\n \n nums=[]\n chars=[]\n \n for c in s:\n if c.isdigit( | Vigneswar_A | NORMAL | 2021-11-28T17:03:03.809378+00:00 | 2021-11-28T17:03:03.809422+00:00 | 42 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n \n nums=[]\n chars=[]\n \n for c in s:\n if c.isdigit():\n nums.append(c)\n else:\n chars.append(c)\n \n if len(nums)==len(chars):\n stri... | 1 | 0 | [] | 0 |
reformat-the-string | C++ || 90 % || COUNTING LETTER AND DIGITS | c-90-counting-letter-and-digits-by-anas_-wpa9 | \n// Algorithm:\n// 1.In this we first count the number of letter and digits in the string .\n// 2.After counting if the difference is >1 return false \n// 3.if | anas_parvez | NORMAL | 2021-11-16T15:46:44.544063+00:00 | 2021-11-16T15:46:44.544090+00:00 | 52 | false | ```\n// Algorithm:\n// 1.In this we first count the number of letter and digits in the string .\n// 2.After counting if the difference is >1 return false \n// 3.if letters are more then the word must start with a letter and vice versa \n// 4.Return the String \n\nclass Solution {\npublic:\n string reformat(string s)... | 1 | 0 | [] | 0 |
reformat-the-string | [Python3] zip() | python3-zip-by-nuno-dev1-t4ez | \nclass Solution:\n def reformat(self, s: str) -> str:\n s1=\'\'.join([x for x in s if x.isalpha()])\n s2=\'\'.join([x for x in s if x.isnumeri | nuno-dev1 | NORMAL | 2021-10-28T19:54:04.595649+00:00 | 2021-10-29T20:44:52.555909+00:00 | 81 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n s1=\'\'.join([x for x in s if x.isalpha()])\n s2=\'\'.join([x for x in s if x.isnumeric()])\n if abs(len(s1)-len(s2))>1: \n return \'\'\n if len(s1)<len(s2):\n s1,s2=s2,s1\n return \'\'.join([x+y for ... | 1 | 0 | [] | 0 |
reformat-the-string | JAVA EASY SOLUTION | java-easy-solution-by-aniket7419-n4m0 | \nclass Solution {\n public String reformat(String s) {\n ArrayList<Character> cha=new ArrayList<Character>();\n ArrayList<Character> in=new Ar | aniket7419 | NORMAL | 2021-10-24T07:36:23.532571+00:00 | 2021-10-24T07:36:23.532616+00:00 | 67 | false | ```\nclass Solution {\n public String reformat(String s) {\n ArrayList<Character> cha=new ArrayList<Character>();\n ArrayList<Character> in=new ArrayList<Character>();\n for(int i=0;i<s.length();i++){\n if(s.charAt(i)>=97)\n cha.add(s.charAt(i));\n else\n ... | 1 | 0 | [] | 0 |
reformat-the-string | Very Easy approach in C++ | very-easy-approach-in-c-by-msy15-s0g3 | \nclass Solution {\npublic:\n string reformat(string s) {\n int n=s.size();\n vector<char>a;\n vector<char>b;\n \n for(int | MSY15 | NORMAL | 2021-10-07T14:41:35.768368+00:00 | 2021-10-07T14:41:35.768417+00:00 | 70 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n int n=s.size();\n vector<char>a;\n vector<char>b;\n \n for(int i=0;i<n;i++)\n {\n if(isalpha(s[i]))\n {\n a.push_back(s[i]);\n }\n else\n {\n ... | 1 | 0 | [] | 0 |
reformat-the-string | Reformat the String | Java | reformat-the-string-java-by-deleted_user-rded | \nclass Solution {\n public String reformat(String s) {\n \n //Edge Case 1: Null string / Length of the string is 0\n if (s.length() == | deleted_user | NORMAL | 2021-09-06T15:21:37.067237+00:00 | 2021-09-06T15:21:37.067292+00:00 | 210 | false | ```\nclass Solution {\n public String reformat(String s) {\n \n //Edge Case 1: Null string / Length of the string is 0\n if (s.length() == 0 || s.length() == 1) {\n return s;\n }\n \n StringBuilder digits = new StringBuilder();\n StringBuilder alphabets = n... | 1 | 0 | ['Java'] | 1 |
reformat-the-string | Java O(N) time, O(1) space, two pointers | java-on-time-o1-space-two-pointers-by-mi-dykb | Instead of copying digits and letters to separate lists, maintain a pointer per type. Final result shouldn\'t count as O(N) space as it\'s not used apart return | migfulcrum | NORMAL | 2021-07-26T07:37:44.346651+00:00 | 2021-07-26T07:38:00.747966+00:00 | 89 | false | Instead of copying digits and letters to separate lists, maintain a pointer per type. Final result shouldn\'t count as O(N) space as it\'s not used apart returning the result.\n\n```\n public String reformat(String s) {\n int n = s.length();\n int digits = 0;\n for(int i = 0; i < n; i++) {\n ... | 1 | 0 | [] | 0 |
reformat-the-string | Java Solution Faster than 87% O(n) | java-solution-faster-than-87-on-by-rar34-i0lu | In this solution I use two Queues here to group both digits and non digits together. You can then loop until both Queues are empty and append the oposite of the | rar349 | NORMAL | 2021-07-16T01:05:16.494088+00:00 | 2021-07-16T01:05:16.494125+00:00 | 78 | false | In this solution I use two Queues here to group both digits and non digits together. You can then loop until both Queues are empty and append the oposite of the last character type onto your result starting with the character type that we have the most of.\n\nThis solution is O(n). It is also important to realize that ... | 1 | 0 | [] | 0 |
reformat-the-string | Java Solution Using StringBuilders and Helper Method to Force Start Larger String | java-solution-using-stringbuilders-and-h-svc9 | ```\npublic String reformat(String s) {\n\tStringBuilder alpha = new StringBuilder();\n\tStringBuilder digit = new StringBuilder();\n\tfor (char c : s.toCharArr | chino8 | NORMAL | 2021-07-09T01:31:09.506468+00:00 | 2021-07-09T01:31:09.506531+00:00 | 61 | false | ```\npublic String reformat(String s) {\n\tStringBuilder alpha = new StringBuilder();\n\tStringBuilder digit = new StringBuilder();\n\tfor (char c : s.toCharArray()) {\n\t\tif (Character.isDigit(c)) {\n\t\t\tdigit.append(c);\n\t\t} else if (Character.isLetter(c)) {\n\t\t\talpha.append(c);\n\t\t}\n\t}\n\n\tif (Math.abs(... | 1 | 0 | [] | 1 |
reformat-the-string | Python 3 : SIMPLE EASY + 36 ms, 97.74% faster | python-3-simple-easy-36-ms-9774-faster-b-qgjz | \nclass Solution:\n def reformat(self, s: str) -> str:\n \n if len(s) > 1 and (s.isalpha() or s.isdigit()) :\n return \'\'\n\n | rohitkhairnar | NORMAL | 2021-07-06T13:48:41.644004+00:00 | 2021-07-06T14:00:16.830502+00:00 | 281 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n \n if len(s) > 1 and (s.isalpha() or s.isdigit()) :\n return \'\'\n\n ints = \'\'\n alpha = \'\'\n for i in s :\n if i.isalpha() :\n alpha += i\n else:\n ints ... | 1 | 0 | ['Python', 'Python3'] | 0 |
reformat-the-string | [Java] Clean Code | java-clean-code-by-algorithmimplementer-998i | ```java\npublic String reformat(String s) {\n\tif (s == null || s.isEmpty()) return s;\n\n\tLinkedList letters = new LinkedList<>();\n\tLinkedList digits = new | algorithmimplementer | NORMAL | 2021-07-01T04:51:10.450685+00:00 | 2021-07-01T04:51:10.450730+00:00 | 67 | false | ```java\npublic String reformat(String s) {\n\tif (s == null || s.isEmpty()) return s;\n\n\tLinkedList<Character> letters = new LinkedList<>();\n\tLinkedList<Character> digits = new LinkedList<>();\n\n\tfor (char ch : s.toCharArray()) {\n\t\tif (Character.isLetter(ch)) letters.add(ch);\n\t\tif (Character.isDigit(ch)) d... | 1 | 0 | [] | 0 |
reformat-the-string | C++ || 0ms runtime || 100% faster 0(N) sol | c-0ms-runtime-100-faster-0n-sol-by-saite-jh1u | \nclass Solution {\npublic:\n string reformat(string s) {\n vector<char> v1;\n vector<char> v2;\n //v1 contains the digits and v2 contai | saiteja_balla0413 | NORMAL | 2021-05-20T13:53:34.968203+00:00 | 2021-05-20T13:53:34.968246+00:00 | 69 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n vector<char> v1;\n vector<char> v2;\n //v1 contains the digits and v2 contains the alphabets\n for(auto c:s)\n {\n if(isdigit(c))\n {\n v1.push_back(c);\n }\n e... | 1 | 0 | [] | 0 |
reformat-the-string | easy c++ solution(with comments) faster than 95% | easy-c-solutionwith-comments-faster-than-jikr | \tclass Solution {\n\tpublic:\n\t\tstring reformat(string s) {\n\t\t\tint n=s.size();\n\t\t\tstring num="";// one for storing digits\n\t\t\tstring alpha="";// o | shubhamsinhanitt | NORMAL | 2021-04-08T17:03:25.571117+00:00 | 2021-04-08T17:03:25.571160+00:00 | 40 | false | \tclass Solution {\n\tpublic:\n\t\tstring reformat(string s) {\n\t\t\tint n=s.size();\n\t\t\tstring num="";// one for storing digits\n\t\t\tstring alpha="";// one for storing characters\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t{\n\t\t\t\tif(isalpha(s[i]))\n\t\t\t\t{\n\t\t\t\t\talpha+=s[i];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{... | 1 | 0 | [] | 0 |
reformat-the-string | Python 3 , Runtime faster than 97.30% and Memory usage less than 89.38% | python-3-runtime-faster-than-9730-and-me-cefq | \nclass Solution:\n def reformat(self, s: str) -> str:\n strs = ""\n nums = ""\n out = ""\n if len(s) == 1 :\n return | sbcyu0421 | NORMAL | 2021-03-02T16:46:35.038431+00:00 | 2021-03-02T16:46:35.038466+00:00 | 170 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n strs = ""\n nums = ""\n out = ""\n if len(s) == 1 :\n return s\n for i in s :\n if ord(i) < 97 :\n nums += i\n else :\n strs += i\n if strs == "" or nu... | 1 | 0 | [] | 0 |
reformat-the-string | [Java] Very easy to understand | java-very-easy-to-understand-by-ra1n-4j1j | \nclass Solution {\n public String reformat(String s) {\n if (s == null || s.length() == 0 || s.length() == 1) {\n return s;\n }\n | ra1n | NORMAL | 2021-02-22T00:52:00.066956+00:00 | 2021-02-22T00:52:00.066985+00:00 | 284 | false | ```\nclass Solution {\n public String reformat(String s) {\n if (s == null || s.length() == 0 || s.length() == 1) {\n return s;\n }\n StringBuilder num = new StringBuilder();\n StringBuilder alpha = new StringBuilder();\n \n for (int i = 0; i < s.length(); i++) {\... | 1 | 1 | [] | 0 |
reformat-the-string | C++ Wiggle sort II same logic. | c-wiggle-sort-ii-same-logic-by-codebush-4shd | \n\nclass Solution {\npublic:\n string reformat(string s) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int | codebush | NORMAL | 2021-01-23T06:52:47.996486+00:00 | 2021-01-23T06:52:47.996516+00:00 | 74 | false | ```\n\n```class Solution {\npublic:\n string reformat(string s) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int n = s.size(),a=0,b=0;\n string s2(s);\n for(int i=0;i<n;i++){\n if(s[i]>=\'0\' and s[i]<=\'9\')a++;\n else b++;\n ... | 1 | 0 | [] | 1 |
reformat-the-string | Python solution | python-solution-by-gabichoi-i2w6 | \tdef reformat(self, s):\n\t\tnumbers = [c for c in s if c.isdigit()]\n letters = [c for c in s if c.isalpha()]\n diff = abs(len(numbers) - len(le | gabichoi | NORMAL | 2021-01-21T08:29:14.499657+00:00 | 2021-01-21T08:29:14.499696+00:00 | 149 | false | \tdef reformat(self, s):\n\t\tnumbers = [c for c in s if c.isdigit()]\n letters = [c for c in s if c.isalpha()]\n diff = abs(len(numbers) - len(letters))\n if len(numbers) > len(letters):\n return self.helper(numbers, letters, diff)\n else:\n return self.helper(letters,... | 1 | 0 | ['Stack', 'Python'] | 0 |
reformat-the-string | Python 3, Zip, Join, Explained | python-3-zip-join-explained-by-lucliu-vekh | Explaination:\nAll letters are in a list, and all digits are in another list.\nUse zip() fucntion to iterate both lists, add the last remaining letter or digit | lucliu | NORMAL | 2020-12-31T02:32:36.763853+00:00 | 2020-12-31T02:32:36.763897+00:00 | 257 | false | Explaination:\nAll letters are in a list, and all digits are in another list.\nUse zip() fucntion to iterate both lists, add the last remaining letter or digit accordingly.\n~~~\nclass Solution:\n def reformat(self, s: str) -> str:\n al, dig, res = "", "", ""\n for c in s:\n if c.isalpha(): ... | 1 | 0 | ['Python3'] | 0 |
reformat-the-string | 4ms easy to understand C++ | 4ms-easy-to-understand-c-by-xzci-cw93 | \nclass Solution {\npublic:\n string reformat(string s) {\n\tstring ans(s.size(), \' \');\n int charnum = 0;\n int num = 0;\n \n bool flag = fal | xzci | NORMAL | 2020-12-25T13:28:22.794846+00:00 | 2020-12-25T13:28:22.794875+00:00 | 81 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n\tstring ans(s.size(), \' \');\n int charnum = 0;\n int num = 0;\n \n bool flag = false;\n for (auto i : s) {\n if(isalpha(i)) \n charnum++; \n else \n num++;\n }\n \n\tif (abs(num ... | 1 | 0 | [] | 0 |
reformat-the-string | My Java Solution with the steps | my-java-solution-with-the-steps-by-vrohi-792k | \n// 1. Create two list for numbers and characters each.\n// 2. If the diff between these two list is >= 2, return "" as we cant get any answer.\n// 3. Use a bo | vrohith | NORMAL | 2020-10-02T14:27:35.331677+00:00 | 2020-10-02T14:27:35.331722+00:00 | 332 | false | ```\n// 1. Create two list for numbers and characters each.\n// 2. If the diff between these two list is >= 2, return "" as we cant get any answer.\n// 3. Use a boolean variable to switch between digit and characters.\n// 4. Always start the first letter with the max count one, ie max(digit, letter) count\n\nclass Solu... | 1 | 0 | ['String', 'Java'] | 0 |
reformat-the-string | c++ using template or func_ptr approaches (8ms , 98.91%) | c-using-template-or-func_ptr-approaches-qpcdd | first determine order (digit or alpha first)\n then take care of no-solution cases\n then use the two iterators to alternate in the found order digits and alpha | michelusa | NORMAL | 2020-09-28T12:12:45.598869+00:00 | 2020-09-29T01:21:43.304634+00:00 | 53 | false | * first determine order (digit or alpha first)\n* then take care of no-solution cases\n* then use the two iterators to alternate in the found order digits and alphas.\nThe add_alphanum takes a function parameter depending if asked to add either digit or alpha\ntemplate approach followed by func_ptr old school approach\... | 1 | 0 | ['C'] | 0 |
reformat-the-string | Rust, 0ms, 100% | rust-0ms-100-by-qiuzhanghua-8by0 | rust\nimpl Solution {\n pub fn reformat(s: String) -> String {\n let v = s.as_bytes();\n let mut v1 = vec![];\n let mut v2 = vec![];\n | qiuzhanghua | NORMAL | 2020-08-28T02:19:52.046086+00:00 | 2020-08-28T02:19:52.046131+00:00 | 71 | false | ```rust\nimpl Solution {\n pub fn reformat(s: String) -> String {\n let v = s.as_bytes();\n let mut v1 = vec![];\n let mut v2 = vec![];\n for ch in v {\n if ch.is_ascii_digit() {\n v1.push(ch)\n } else {\n v2.push(ch);\n }\n ... | 1 | 0 | [] | 0 |
reformat-the-string | JavaScript - O (n) 2 loops | javascript-o-n-2-loops-by-bernardsean-xj9e | \nTime complexity: O (s.length) + O (alphabet array.length) = O (n)\nSpace Complexity: O(s.length) = O (n);\n/**\n * @param {string} s\n * @return {string}\n */ | bernardsean | NORMAL | 2020-08-26T03:15:32.455747+00:00 | 2020-08-27T15:53:49.090133+00:00 | 50 | false | ```\nTime complexity: O (s.length) + O (alphabet array.length) = O (n)\nSpace Complexity: O(s.length) = O (n);\n/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n const al = [], nums = [];\n for (let ss of s.split(\'\')) {\n if (ss % 1 === 0) {\n nums.push(ss);\n } else {\n... | 1 | 1 | [] | 0 |
reformat-the-string | JavaScript O(N) solution | javascript-on-solution-by-illitirit-hk52 | \nvar reformat = function(s) {\n if (s.length <= 1) return s;\n \n const result = [];\n const letters = s.match(/[a-zA-Z]/g) || [];\n const nums = s.match( | illitirit | NORMAL | 2020-07-17T18:38:17.046733+00:00 | 2020-07-17T18:38:33.279473+00:00 | 172 | false | ```\nvar reformat = function(s) {\n if (s.length <= 1) return s;\n \n const result = [];\n const letters = s.match(/[a-zA-Z]/g) || [];\n const nums = s.match(/[0-9]/g) || [];\n \n if (!letters.length || !nums.length) return \'\'\n \n const larger = letters.length > nums.length ? \'letters\' : \'nums\';\n\n wh... | 1 | 0 | ['JavaScript'] | 0 |
reformat-the-string | Simple basic flow seperate lists | simple-basic-flow-seperate-lists-by-soha-4yip | ```\n\nclass Solution:\n def reformat(self, s: str) -> str:\n letters =""\n digits = ""\n for ch in s:\n if \'a\'<= ch <=\'z\ | soham9 | NORMAL | 2020-07-14T02:59:31.838944+00:00 | 2020-07-14T03:03:10.402049+00:00 | 177 | false | ```\n\nclass Solution:\n def reformat(self, s: str) -> str:\n letters =""\n digits = ""\n for ch in s:\n if \'a\'<= ch <=\'z\':\n letters +=ch\n else:\n digits +=ch\n \n if len(digits) == 1:\n return digits\n ... | 1 | 0 | ['Python3'] | 0 |
reformat-the-string | [Java] Concise solution. | java-concise-solution-by-nkallen-kasn | \nclass Solution {\n public String reformat(String s) {\n Queue<Character> q1 = new LinkedList<>(), q2 = new LinkedList<>();\n for(char c : s.t | nkallen | NORMAL | 2020-07-12T04:29:29.770245+00:00 | 2020-07-12T04:29:29.770315+00:00 | 85 | false | ```\nclass Solution {\n public String reformat(String s) {\n Queue<Character> q1 = new LinkedList<>(), q2 = new LinkedList<>();\n for(char c : s.toCharArray()){\n if(Character.isLetter(c)){\n q1.offer(c);\n }else q2.offer(c);\n }\n if(Math.abs(q1.size(... | 1 | 0 | [] | 0 |
reformat-the-string | Python3 two solutions time O(n), space O(n) and time O(n), space O(1) | python3-two-solutions-time-on-space-on-a-p2ri | 2 lists: time O(n), space O(n)\n\n def reformat(self, s: str) -> str:\n digits, chars = [], []\n for c in s:\n if c.isdigit():\n | dhxia | NORMAL | 2020-06-05T02:15:32.394891+00:00 | 2020-06-05T14:54:13.329783+00:00 | 87 | false | 2 lists: time O(n), space O(n)\n```\n def reformat(self, s: str) -> str:\n digits, chars = [], []\n for c in s:\n if c.isdigit():\n digits.append(c)\n else:\n chars.append(c)\n nD, nC = len(digits), len(chars)\n if -1 <= nD - nC <= 1:\n ... | 1 | 0 | [] | 0 |
reformat-the-string | C# very ugly solution, please don't judge | c-very-ugly-solution-please-dont-judge-b-zjfa | Using two stacks I can compare the counts and then use the stacks to pop off in the required order\ni once again check near the end to decide if I have to pop a | nikolatesla20 | NORMAL | 2020-05-23T19:09:03.723930+00:00 | 2020-05-23T19:09:03.723983+00:00 | 49 | false | Using two stacks I can compare the counts and then use the stacks to pop off in the required order\ni once again check near the end to decide if I have to pop an extra off or not. That part of the code is not optimized, I probably only need to check once at the end, which stack requires an extra pop\n\n```\npublic clas... | 1 | 0 | [] | 0 |
reformat-the-string | straight forward python | straight-forward-python-by-goodfine1210-3r1r | \nclass Solution:\n def reformat(self, s: str) -> str:\n \n alp = []\n num = []\n res = []\n \n for l in s:\n | goodfine1210 | NORMAL | 2020-05-09T23:27:26.695812+00:00 | 2020-05-09T23:28:09.223064+00:00 | 79 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n \n alp = []\n num = []\n res = []\n \n for l in s:\n if l.isalpha():\n alp.append(l)\n\t\t\t\t\n if l.isnumeric():\n num.append(l)\n \n if ab... | 1 | 0 | [] | 0 |
reformat-the-string | JavaScript Easy Intuitive Soluttion | javascript-easy-intuitive-soluttion-by-d-0jme | The idea is, \n1. Loop over the string and store data in two arrays, one with alphabets, another with numbers.\n2. if the diff of size is > 1, so permutation no | dibyajyoti_ghosal | NORMAL | 2020-05-09T19:32:26.661219+00:00 | 2020-05-09T19:32:26.661261+00:00 | 118 | false | The idea is, \n1. Loop over the string and store data in two arrays, one with alphabets, another with numbers.\n2. if the diff of size is > 1, so permutation not possible.\n3. decide which one is larger array and which one is smaller.\n4. loop over the length of the larger array, push the element in the larger array fi... | 1 | 0 | [] | 0 |
reformat-the-string | C++ nothing clever 96% Speed, 100% Memory | c-nothing-clever-96-speed-100-memory-by-3f1mc | \nclass Solution {\npublic:\n string reformat(string s) {\n \n //Separate digits and letters\n string digi = "";\n string lett = | adrianlee0118 | NORMAL | 2020-04-26T00:10:52.083596+00:00 | 2020-04-26T00:10:52.083632+00:00 | 100 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n \n //Separate digits and letters\n string digi = "";\n string lett = "";\n for (auto& c : s){\n if (isdigit(c)) digi+=c;\n else lett += c;\n }\n \n //If difference in size of d... | 1 | 0 | [] | 0 |
divide-intervals-into-minimum-number-of-groups | Min Heap | min-heap-by-votrubac-6q0v | We use a min heap to track the rightmost number of each group.\n\nFirst, we sort the intervals. Then, for each interval, we check if the top of the heap is less | votrubac | NORMAL | 2022-09-11T04:00:49.226267+00:00 | 2022-09-13T05:26:43.251735+00:00 | 13,728 | false | We use a min heap to track the rightmost number of each group.\n\nFirst, we sort the intervals. Then, for each interval, we check if the top of the heap is less than **left**.\n\nIf it is, we can add that interval to an existing group: pop from the heap, and push **right**, updating the rightmost number of that group.\... | 331 | 3 | ['C', 'Python3'] | 36 |
divide-intervals-into-minimum-number-of-groups | [Java/C++/Python] Meeting Room | javacpython-meeting-room-by-lee215-bzv8 | Intuition\nExactly same as meeting rooms.\n\n\n# Explanation\nAt time point intervals[i][0],\nstart using a meeting room(group).\n\nAt time point intervals[i][1 | lee215 | NORMAL | 2022-09-11T04:02:37.691941+00:00 | 2022-09-11T04:02:37.691985+00:00 | 13,838 | false | # **Intuition**\nExactly same as meeting rooms.\n<br>\n\n# **Explanation**\nAt time point `intervals[i][0]`,\nstart using a meeting room(group).\n\nAt time point `intervals[i][1] + 1`,\nend using a meeting room.\n\nSort all events by time,\nand accumulate the number of room(group) used.\n<br>\n\n# **Complexity**\nTime ... | 166 | 3 | ['C', 'Python', 'Java'] | 32 |
divide-intervals-into-minimum-number-of-groups | C++ Easy Solution | c-easy-solution-by-ayush_gupta4-qahh | \n\n\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& a) {\n int ans=0, i, n=1000011;\n vector<int> A(n, 0); // Taken the Array | ayush_gupta4 | NORMAL | 2022-09-11T06:16:11.752986+00:00 | 2022-09-11T06:38:55.152331+00:00 | 3,956 | false | \n\n```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& a) {\n int ans=0... | 91 | 1 | [] | 16 |
divide-intervals-into-minimum-number-of-groups | Beats 100% TC & SC | Simple and Easy to understand | Python | CPP | Java | beats-100-tc-sc-simple-and-easy-to-under-n2is | Intuition\nWe need to group intervals so that no intervals in the same group overlap. By sorting start and end times, we can track how many intervals overlap at | Baslik69 | NORMAL | 2024-10-12T00:10:20.506955+00:00 | 2024-10-12T00:10:20.506976+00:00 | 25,061 | false | # Intuition\nWe need to group intervals so that no intervals in the same group overlap. By sorting start and end times, we can track how many intervals overlap at any point. If a new interval starts after an earlier one ends, we can reuse that group. Otherwise, we need a new group.\n\n# Approach\n1. **Sort start and en... | 86 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Sorting', 'Python', 'C++', 'Java', 'Python3'] | 22 |
divide-intervals-into-minimum-number-of-groups | C++ | Line Sweep | Related Problems | c-line-sweep-related-problems-by-kiranpa-gnws | Use Line Sweep\n- Return the maximum element in the entire range.\ncpp\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n\n | kiranpalsingh1806 | NORMAL | 2022-09-11T04:00:46.880895+00:00 | 2022-09-11T10:24:44.683885+00:00 | 4,099 | false | - Use Line Sweep\n- Return the maximum element in the entire range.\n```cpp\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n\n int line[1000005] = {};\n int maxEle = -1;\n\n for(auto &e : intervals) {\n int start = e[0], end = e[1];\n line[star... | 76 | 1 | ['C', 'Prefix Sum', 'C++'] | 8 |
divide-intervals-into-minimum-number-of-groups | 🌟 Step-by-Step Guide to Minimizing Interval Groups 🔥💯 | step-by-step-guide-to-minimizing-interva-9ptm | \n\n## \uD83C\uDF1F Access Daily LeetCode Solutions Repo : click here\n\n---\n\n\n\n---\n\n# Intuition\nThe problem asks us to group overlapping intervals such | withaarzoo | NORMAL | 2024-10-12T00:38:08.076352+00:00 | 2024-10-12T00:38:08.076386+00:00 | 6,881 | false | \n\n## \uD83C\uDF1F **Access Daily LeetCode Solutions Repo :** [click here](https://github.com/withaarzoo/LeetCode-Solutions)\n\n---\n\n {\n\t\t// Sort intervals based on the start\n sort(intervals.begin(), inte | _Potter_ | NORMAL | 2022-09-11T04:18:09.222190+00:00 | 2022-09-12T05:28:26.667986+00:00 | 3,103 | false | ```\nclass Solution {\npublic:\n int minGroups(vector<vector<int>>& intervals) {\n\t\t// Sort intervals based on the start\n sort(intervals.begin(), intervals.end());\n \n\t\t// Heap stores the ending interval of each group\n priority_queue<int,vector<int>,greater<int>> heap;\n \n ... | 38 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 4 |
divide-intervals-into-minimum-number-of-groups | [Java] 🔥🔥37ms 100%🔥🔥 || Meeting Room II || 1 line | java-37ms-100-meeting-room-ii-1-line-by-k5jzw | Exactly the same as 253. Meeting Rooms II\n37ms submission\n# method 1\nI put in neccesary comments hopefully it\'s easy enough to understand, just 1 line core | byegates | NORMAL | 2022-09-12T07:08:27.401828+00:00 | 2022-09-18T08:27:23.137941+00:00 | 1,504 | false | Exactly the same as [253. Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii/)\n[37ms submission](https://leetcode.com/submissions/detail/802726465/)\n# method 1\nI put in neccesary comments hopefully it\'s easy enough to understand, just 1 line core logic\n```java\nclass Solution {\n public int minGro... | 26 | 0 | ['Greedy', 'Java'] | 3 |
divide-intervals-into-minimum-number-of-groups | 😉Very Easy Clean Code + Full Intution & Thought Process + illustrations | very-easy-clean-code-full-intution-thoug-bro7 | Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/mqI9LHEBih0?si=oQ_320SzapIjMLg4\n\n> Solution w | Rarma | NORMAL | 2024-10-12T07:23:04.366722+00:00 | 2024-10-12T08:37:49.710708+00:00 | 2,278 | false | # Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/mqI9LHEBih0?si=oQ_320SzapIjMLg4\n\n> Solution will be Easy, You just need to Go on each slides giving a read\n# Intuition & Approach\n', 'Ordered Set', 'C++', 'Java', 'Python3'] | 4 |
divide-intervals-into-minimum-number-of-groups | [Java] Prefix Sum | smart trick with +1 and -1 | java-prefix-sum-smart-trick-with-1-and-1-zmt5 | \nclass Solution {\n public int minGroups(int[][] intervals) {\n int[] count = new int[1000002];\n \n for(int[] in : intervals){\n | a_lone_wolf | NORMAL | 2022-09-11T04:00:39.640217+00:00 | 2022-09-11T04:01:20.811120+00:00 | 1,660 | false | ```\nclass Solution {\n public int minGroups(int[][] intervals) {\n int[] count = new int[1000002];\n \n for(int[] in : intervals){\n count[in[0]]++;\n count[in[1]+1]--;\n }\n \n int max = 0;\n \n for(int i = 1; i < 1000002; i++){\n ... | 21 | 0 | ['Prefix Sum'] | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.