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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
longest-palindrome | Simple Java Solution in One Pass | simple-java-solution-in-one-pass-by-nosy-nils | Count duplicates in the pass, then check if we have an extra character to fix in the middle.\n\npublic int longestPalindrome(String s) {\n boolean[] map | nosydev | NORMAL | 2016-10-03T04:28:28.347000+00:00 | 2018-10-09T00:58:16.021143+00:00 | 7,776 | false | Count duplicates in the pass, then check if we have an extra character to fix in the middle.\n```\npublic int longestPalindrome(String s) {\n boolean[] map = new boolean[128];\n int len = 0;\n for (char c : s.toCharArray()) {\n map[c] = !map[c]; // flip on each occurrence, false ... | 33 | 0 | [] | 5 |
longest-palindrome | [C++] solution | c-solution-by-naniko19-2cbo | \nclass Solution {\npublic:\n int longestPalindrome(string s) {\n unordered_map<int,int> mp;\n int res = 0;\n for(int i = 0; i < s.lengt | naniko19 | NORMAL | 2020-08-15T00:41:36.703462+00:00 | 2020-08-15T00:41:36.703496+00:00 | 4,273 | false | ```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n unordered_map<int,int> mp;\n int res = 0;\n for(int i = 0; i < s.length(); i++) {\n mp[s[i]]++;\n if(mp[s[i]]%2==0) {\n res += mp[s[i]];\n mp[s[i]] = 0;\n }\n ... | 27 | 1 | ['C', 'C++'] | 2 |
longest-palindrome | Python 3(Two-liner) - Faster than 99.26%, Memory usage less than 100% | python-3two-liner-faster-than-9926-memor-go1j | \nfrom collections import Counter\n\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n count = sum([(x//2) * 2 for x in Counter(s).value | mmbhatk | NORMAL | 2019-11-20T13:21:53.424289+00:00 | 2019-11-20T13:24:07.739178+00:00 | 3,991 | false | ```\nfrom collections import Counter\n\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n count = sum([(x//2) * 2 for x in Counter(s).values()])\n return count if count == len(s) else (count + 1)\n``` | 26 | 0 | ['Python', 'Python3'] | 4 |
longest-palindrome | Easy to understand accepted solution with explanation | easy-to-understand-accepted-solution-wit-81ce | First, characters are counted. Even occurring characters (v[i]%2 == 0) can always be used to build a palindrome. For every odd occurring character (v[i]%2 == 1) | vsmnv | NORMAL | 2016-10-02T05:52:07.096000+00:00 | 2018-10-12T02:08:05.557471+00:00 | 9,048 | false | First, characters are counted. Even occurring characters (v[i]%2 == 0) can always be used to build a palindrome. For every odd occurring character (v[i]%2 == 1), v[i]-1 characters can be used. Res is incremented if there is at least one character with odd occurrence number.\n```\n int longestPalindrome(string s) {\n... | 26 | 0 | [] | 7 |
longest-palindrome | Simple Java Solution | simple-java-solution-by-fabrizio3-f4ne | \npublic int longestPalindrome(String s) {\n\tif(s==null || s.length()==0) return 0;\n\tSet<Character> set = new HashSet<>();\n\tint count = 0;\n\tchar[] chars | fabrizio3 | NORMAL | 2016-10-03T06:10:49.358000+00:00 | 2016-10-03T06:10:49.358000+00:00 | 3,274 | false | ```\npublic int longestPalindrome(String s) {\n\tif(s==null || s.length()==0) return 0;\n\tSet<Character> set = new HashSet<>();\n\tint count = 0;\n\tchar[] chars = s.toCharArray();\n\tfor(char c: chars) {\n\t\tif(set.remove(c)) {\n\t\t\tcount++;\n\t\t} else {\n\t\t\tset.add(c);\n\t\t}\n\t}\n\treturn set.isEmpty() ? co... | 25 | 0 | ['Hash Table', 'Java'] | 4 |
longest-palindrome | Count Freq vs Even or Odd||0ms beats 100% | count-freq-vs-even-or-odd0ms-beats-100-b-wl88 | Intuition\n Describe your first thoughts on how to solve this problem. \nAt most one alphabet has an odd number of occurrencies in a palindrome string.\n\n2nd a | anwendeng | NORMAL | 2024-06-04T01:57:02.563293+00:00 | 2024-06-04T09:33:47.968624+00:00 | 6,205 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAt most one alphabet has an odd number of occurrencies in a palindrome string.\n\n2nd approach uses bitset/long long & consider only the parity ( odd or even frequencies). C, C++ & Python are implemented.\n# Approach\n<!-- Describe your a... | 22 | 0 | ['Array', 'String', 'Bit Manipulation', 'C', 'C++', 'Python3'] | 7 |
longest-palindrome | C / C++ Solution O(n) time, O(1) space, 100.00% faster! | c-c-solution-on-time-o1-space-10000-fast-3x8v | C Solution\n\n\nint longestPalindrome(char * s)\n{\n int letters[52] = {0};\n bool is_odd = false;\n int longest_palindrome = 0;\n \n | debbiealter | NORMAL | 2020-08-14T08:52:17.124445+00:00 | 2020-08-14T09:23:30.393198+00:00 | 3,142 | false | # C Solution\n\n```\nint longestPalindrome(char * s)\n{\n int letters[52] = {0};\n bool is_odd = false;\n int longest_palindrome = 0;\n \n for(int i = 0; i < strlen(s); i++)\n {\n if(*(s + i) <= \'Z\')\n letters[*(s + i) -\'A\']++;\n \n ... | 21 | 1 | [] | 3 |
longest-palindrome | Python Solution with Explanation | python-solution-with-explanation-by-cody-ihsg | Assume character frequency = K\n\n1. If all the characters appears even times, then we just add up all the frequencies (K) and returns the result.\n\n\tEx. aabb | codyli520 | NORMAL | 2020-09-22T08:07:49.346757+00:00 | 2020-09-22T08:12:06.873718+00:00 | 2,096 | false | Assume character frequency = K\n\n1. If all the characters appears even times, then we just add up all the frequencies (K) and returns the result.\n\n\tEx. aabb -> abba\n\n2. If one or more characters appears odd times, we noted down that an odd frequency character had appeared, and just increment result `K-1` (since o... | 20 | 0 | ['Python'] | 3 |
longest-palindrome | Simple Java beat 99.67% | simple-java-beat-9967-by-erintao-q2q0 | \npublic int longestPalindrome(String s) {\n int[] chars = new int[128];\n char[] t = s.toCharArray();\n for(char c:t){\n chars[ | ErinTao | NORMAL | 2017-06-06T05:00:25.221000+00:00 | 2018-09-18T03:10:52.464830+00:00 | 2,441 | false | ```\npublic int longestPalindrome(String s) {\n int[] chars = new int[128];\n char[] t = s.toCharArray();\n for(char c:t){\n chars[c]++;\n }\n int single = 0;\n for(int n:chars){\n if(n%2!=0){\n single++;\n }\n }\n r... | 19 | 0 | [] | 4 |
longest-palindrome | Simplest solution using HashSet | simplest-solution-using-hashset-by-abste-u1u2 | Intuition\nIn palindromes with even number of characters each of them must have a pair. We can use HashSet, then add and remove the same character, and at the t | abster2970 | NORMAL | 2023-01-30T18:29:29.319165+00:00 | 2023-01-30T18:42:45.083803+00:00 | 789 | false | # Intuition\nIn palindromes with even number of characters each of them must have a pair. We can use HashSet, then add and remove the same character, and at the time of removal that will be +2 to our overall length. \n\nIf in the end our set is not empty, no matter how many unique characters will be left over, it can b... | 18 | 0 | ['C#'] | 0 |
longest-palindrome | JAVA | 3 Approaches | Everything you'd need ✅ | java-3-approaches-everything-youd-need-b-xmxn | Please Upvote :D\n---\n##### 1. Using HashSet:\njava []\nclass Solution {\n public int longestPalindrome(String s) {\n Set<Character> set = new HashSe | sourin_bruh | NORMAL | 2022-10-17T12:40:50.929812+00:00 | 2023-01-08T06:35:27.493702+00:00 | 2,641 | false | # Please Upvote :D\n---\n##### 1. Using HashSet:\n``` java []\nclass Solution {\n public int longestPalindrome(String s) {\n Set<Character> set = new HashSet<>();\n int len = 0;\n for (char c : s.toCharArray()) {\n if (set.contains(c)) {\n len += 2;\n set... | 18 | 0 | ['Array', 'Hash Table', 'Java'] | 5 |
longest-palindrome | 🔥Most Easy Solution | [JAVA] | HashSet🤗 | most-easy-solution-java-hashset-by-dipes-j9us | 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 | dipesh_12 | NORMAL | 2023-01-11T09:00:59.985897+00:00 | 2023-01-11T09:00:59.985950+00:00 | 3,256 | 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)$$ --... | 17 | 0 | ['Java'] | 4 |
longest-palindrome | Python || counter || explanation | python-counter-explanation-by-palashbajp-hh5z | Upvote if u like\n\n1. Count occurance of all characters\n2. If character occurs even times , add their count\n3. If character occurs odd times , add count-1 an | palashbajpai214 | NORMAL | 2022-07-01T04:33:48.497868+00:00 | 2022-07-01T04:33:48.497897+00:00 | 1,761 | false | ***Upvote if u like***\n\n1. Count occurance of all characters\n2. If character occurs even times , add their count\n3. If character occurs odd times , add count-1 and make oddFlag=1\n4. Palindrom can maximum have one odd occurance, at middle , so if oddFlag=1 return ans+1\n\n\n```\nclass Solution:\n def longestPali... | 17 | 0 | ['Python', 'Python3'] | 4 |
longest-palindrome | C++ So easy .. | c-so-easy-by-ravi0077-vj80 | We can include all even frequency characters in our palindrome.\nWe can include atmost one odd frequency characters to make a palindrome\n\nclass Solution {\npu | ravi0077 | NORMAL | 2020-08-14T07:04:54.632612+00:00 | 2020-08-19T07:14:14.313143+00:00 | 837 | false | We can include all even frequency characters in our palindrome.\nWe can include atmost one odd frequency characters to make a palindrome\n```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n \n vector<int>v(255,0);\n int c=0;\n for(int i=0;i<s.size();i++)\n {\n ... | 17 | 17 | [] | 3 |
longest-palindrome | PYTHON - 35ms 99th percentile O(n) solution | python-35ms-99th-percentile-on-solution-4npvc | \n\nclass Solution(object):\n\n def longestPalindrome(self, s):\n """\n :type s: str\n :rtype: int\n """\n ctmap = {}\n | moonstone1011 | NORMAL | 2016-10-28T17:29:17.346000+00:00 | 2018-10-08T09:04:23.078013+00:00 | 4,494 | false | \n\nclass Solution(object):\n\n def longestPalindrome(self, s):\n """\n :type s: str\n :rtype: int\n """\n ctmap = {}\n for c in s:\n if c not in ctmap:\n ctmap[c] = 1\n else:\n ctmap[c] += 1\n\n ret = 0\n sin... | 17 | 0 | [] | 4 |
longest-palindrome | Simple Python O(N) solution using Counter | simple-python-on-solution-using-counter-nbzb3 | To solve this problem we need to identify the underlying structure of palindromes. A palindrome can either be made up of just characters which are present on bo | bloomh | NORMAL | 2022-10-02T18:36:54.224750+00:00 | 2022-10-02T18:36:54.224831+00:00 | 1,772 | false | To solve this problem we need to identify the underlying structure of palindromes. A palindrome can either be made up of just characters which are present on both sides of the middle, or it can be created from these symmetrical characters while having a character which sits directly in the middle. That is, in a palindr... | 15 | 0 | ['Python'] | 1 |
longest-palindrome | C# HashSet solution | c-hashset-solution-by-newbiecoder1-gw7a | Time complexity: O(n)\nSpace complexity: O(1)\n\npublic class Solution {\n public int LongestPalindrome(string s) {\n \n if(s == null || s.Leng | newbiecoder1 | NORMAL | 2020-08-15T23:33:12.566079+00:00 | 2020-08-15T23:33:12.566124+00:00 | 611 | false | Time complexity: O(n)\nSpace complexity: O(1)\n```\npublic class Solution {\n public int LongestPalindrome(string s) {\n \n if(s == null || s.Length == 0)\n return 0;\n \n int len = 0;\n HashSet<char> set = new HashSet<char>();\n foreach(char c in s)\n {\n ... | 14 | 0 | [] | 2 |
longest-palindrome | C : beats 100%, 4-lines, simple n short, no built-in Utils/Data Structures, O(1)S O(n)T | c-beats-100-4-lines-simple-n-short-no-bu-y0ht | NOTE : Whoever downvoted this, it is clear that you failed to understand the code here since it requires a seasoned C programmer to appreciate it. So, if you do | universalcoder12 | NORMAL | 2020-08-15T05:29:03.322154+00:00 | 2020-08-15T07:23:03.461789+00:00 | 494 | false | **NOTE :** Whoever downvoted this, it is clear that you ***failed*** to understand the code here since it requires a seasoned C programmer to appreciate it. So, if you ***don\'t*** understand, move on, but do \\****not***\\* just downvote to show your frustration. Period.\n\n```\nint longestPalindrome(char * s){\n i... | 14 | 2 | ['C'] | 0 |
longest-palindrome | C# LINQ-based 2-liner | c-linq-based-2-liner-by-vlassov-insw | \n public int LongestPalindrome(string s) {\n var even = s.GroupBy(c => c).Select(g => g.Count() & ~1).Sum();\n return even < s.Length ? even + | vlassov | NORMAL | 2020-08-14T09:57:32.972105+00:00 | 2020-08-15T20:14:24.626772+00:00 | 370 | false | ```\n public int LongestPalindrome(string s) {\n var even = s.GroupBy(c => c).Select(g => g.Count() & ~1).Sum();\n return even < s.Length ? even + 1 : even;\n }\n``` | 14 | 0 | [] | 0 |
longest-palindrome | 🏆EASY SOLUTION || Simple Approach || C++ || PYTHON || JAVA🔥🚀💯 | easy-solution-simple-approach-c-python-j-c7h9 | \n\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1.Count Character Frequencie | nikhil73995 | NORMAL | 2024-06-04T00:17:59.259710+00:00 | 2024-06-04T06:23:35.875165+00:00 | 4,557 | false | \n\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.Count Character Frequencies:\n\n ->Create a frequency map (HashMap or unordered_map) to count character frequencies.\n ->Iterate through each character in the string.... | 13 | 1 | ['Hash Table', 'String', 'Greedy', 'C++', 'Java', 'Python3'] | 11 |
longest-palindrome | C++ solution using map, with explanations - O(n) time, O(1) space - faster than 96% | c-solution-using-map-with-explanations-o-ty2i | \nclass Solution {\npublic:\n int longestPalindrome(string s) {\n int res = 0;\n unordered_map<char, int> map;\n for (int i=0; i<s.size( | yehudisk | NORMAL | 2020-08-14T08:34:09.298353+00:00 | 2020-08-14T08:35:14.001356+00:00 | 1,802 | false | ```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n int res = 0;\n unordered_map<char, int> map;\n for (int i=0; i<s.size(); i++) // save in map the amount of each letter in s\n {\n map[s[i]]++;\n }\n bool flag = false;\n for (auto x : map)... | 13 | 0 | ['C', 'C++'] | 2 |
longest-palindrome | [C++] Concise Solution Explained, 100% Time, ~99% Space | c-concise-solution-explained-100-time-99-wwnz | Okay, this is a nice, simple one: first of all we build our own usual frequency map, then we go through it, taking each frequency and rounding it down to the ne | ajna | NORMAL | 2019-11-22T17:46:08.340968+00:00 | 2020-08-14T07:49:49.269613+00:00 | 1,754 | false | Okay, this is a nice, simple one: first of all we build our own usual frequency map, then we go through it, taking each frequency and rounding it down to the next multiple of `2` before adding it to our accumulator variable `res`.\n\nNotice that I did it with bitwise operators just to show off, but `res += e.second >> ... | 13 | 2 | ['C', 'Counting', 'C++'] | 3 |
longest-palindrome | [Python] Hash Table faster than 99.88% | python-hash-table-faster-than-9988-by-is-bfl7 | Upvote If you like it \uFF1A\uFF09\n\n\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n count = {} # Hash Table \n ans = [] | isu10903027A | NORMAL | 2022-11-20T10:10:46.336007+00:00 | 2022-11-20T10:29:35.332112+00:00 | 3,773 | false | Upvote If you like it \uFF1A\uFF09\n\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n count = {} # Hash Table \n ans = [] # every word\'s frequency \n odd= 0 # store an odd number\'s frequency \n for word in s:\n if word not in count:\n ... | 12 | 0 | ['Hash Table', 'Python', 'Python3'] | 1 |
longest-palindrome | 🔥Easiest Solution➡️All Language🔥🔥 | easiest-solutionall-language-by-sharma_2-r7c8 | Intuition\npython []\nclass Solution(object):\n def longestPalindrome(self, s):\n """\n :type s: str\n :rtype: int\n """\n | Sharma_290 | NORMAL | 2024-06-04T00:16:43.867526+00:00 | 2024-06-04T00:16:43.867546+00:00 | 2,719 | false | # Intuition\n```python []\nclass Solution(object):\n def longestPalindrome(self, s):\n """\n :type s: str\n :rtype: int\n """\n from collections import Counter\n \n counts = Counter(s)\n length = 0\n has_odd = False\n \n for count in counts... | 11 | 0 | ['Python', 'C++', 'Java'] | 12 |
longest-palindrome | C++ 3 lines bit manipulations beats all | c-3-lines-bit-manipulations-beats-all-by-pe2w | The theory is very simple: we XOR each letter to its position, at the end, each 1 left stands for "there exists odd number of that letter".\ntotal number of let | alvin-777 | NORMAL | 2020-09-22T02:04:41.939851+00:00 | 2020-09-22T02:04:41.939894+00:00 | 514 | false | The theory is very simple: we XOR each letter to its position, at the end, each `1` left stands for "there exists odd number of that letter".\n`total number of letters` - `single letter(s) cannot be paired` + `if there is any single letter we can put ONE in the centre of the palindrome`\n\n```cpp\nint longestPalindrome... | 11 | 1 | ['Bit Manipulation', 'C'] | 0 |
longest-palindrome | 5 lines C++ | 5-lines-c-by-vesion-2j7d | \nclass Solution {\npublic:\n int longestPalindrome(string s) {\n vector<int> m(256, 0); \n for (auto& c : s) m[c-'\\0']++;\n int | vesion | NORMAL | 2016-10-02T06:48:14.283000+00:00 | 2018-09-25T12:58:52.714836+00:00 | 6,280 | false | ```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n vector<int> m(256, 0); \n for (auto& c : s) m[c-'\\0']++;\n int result = 0;\n for (auto& i : m) result += i%2 ? (result%2 ? i-1 : i) : i;\n return result;\n }\n};\n``` | 11 | 0 | [] | 4 |
longest-palindrome | JAVASCRIPT✅EASY EXPLANATION✅[58ms]✅94.22%BEATS | javascripteasy-explanation58ms9422beats-66vqe | \n\n# Explanation\n1. The function takes a string s as input and initializes a variable answer to 0, which will be used to store the length of the longest palin | ikboljonme | NORMAL | 2023-03-31T00:22:30.060081+00:00 | 2023-03-31T00:22:30.060123+00:00 | 2,067 | false | \n\n# Explanation\n1. The function takes a string s as input and initializes a variable answer to 0, which will be used to store the length of the longest palindrome.\n\n2. An em... | 10 | 0 | ['JavaScript'] | 0 |
longest-palindrome | JS || Single Loop || HashMap | js-single-loop-hashmap-by-shaanaliyev-wzwx | \n/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindrome = function(s) {\n let result = 0;\n const mem = new Set();\n for(let i=0; | 20250306.123qweasdcxz | NORMAL | 2023-03-09T21:00:19.740121+00:00 | 2023-03-09T21:00:19.740156+00:00 | 1,926 | false | ```\n/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindrome = function(s) {\n let result = 0;\n const mem = new Set();\n for(let i=0; i<s.length; i++) {\n if(mem.has(s[i])) {\n result+=2;\n mem.delete(s[i]);\n } else { \n mem.add(s[i]);\n ... | 10 | 0 | ['JavaScript'] | 4 |
longest-palindrome | 409: Solution with step by step explanation | 409-solution-with-step-by-step-explanati-1b99 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Initialize an empty dictionary freq_dict to store the frequency of eac | Marlen09 | NORMAL | 2023-03-06T04:06:43.242408+00:00 | 2023-03-06T04:06:43.242460+00:00 | 4,529 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Initialize an empty dictionary freq_dict to store the frequency of each character in the string s.\n2. Iterate over each character char in the string s and add it to the dictionary freq_dict if it doesn\'t exist, or incre... | 10 | 0 | ['Hash Table', 'String', 'Greedy', 'Python', 'Python3'] | 1 |
longest-palindrome | C++ solution using hashmap ✅ | c-solution-using-hashmap-by-coding_menan-trge | Logic\nAll elements on either side of the palindrome have to be even if number so that thay can equally be distributed on each side. Other than the only element | coding_menance | NORMAL | 2022-10-13T11:56:10.767009+00:00 | 2022-10-31T11:15:05.621197+00:00 | 1,718 | false | # Logic\nAll elements on either side of the palindrome have to be even if number so that thay can equally be distributed on each side. Other than the only element which can have odd number of times repeated is the one at the middle in case of a string of odd length.\n\n*Example: ababcccbaba*\n\nOther than c all other e... | 10 | 0 | ['Hash Table', 'C++'] | 4 |
longest-palindrome | JAVA 100% Faster Solution | java-100-faster-solution-by-abhishekpate-q3jm | \nclass Solution {\n public int longestPalindrome(String s) {\n int[] freq = new int[256];\n for (char c : s.toCharArray()) freq[c]++;\n\n | abhishekpatel_ | NORMAL | 2021-07-21T03:57:44.288000+00:00 | 2021-07-21T03:57:44.288033+00:00 | 924 | false | ```\nclass Solution {\n public int longestPalindrome(String s) {\n int[] freq = new int[256];\n for (char c : s.toCharArray()) freq[c]++;\n\n int even = 0, odd = 0;\n for (int i = 0; i < 256; i++) {\n if (freq[i] % 2 == 0) even += freq[i];\n else {\n e... | 10 | 0 | ['Java'] | 1 |
longest-palindrome | Python | Easy | python-easy-by-khosiyat-hgnw | see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n char_count = {}\n \n | Khosiyat | NORMAL | 2024-06-04T05:04:23.811173+00:00 | 2024-06-04T05:04:23.811201+00:00 | 1,351 | false | [see the Successfully Accepted Submission](https://leetcode.com/problems/longest-palindrome/submissions/1277058488/?envType=daily-question&envId=2024-06-04)\n\n# Code\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n char_count = {}\n \n # Count frequency of each character\n ... | 9 | 0 | ['Python3'] | 1 |
longest-palindrome | Python 3 || 3 lines, Counter || T/S: 99% / 98% | python-3-3-lines-counter-ts-99-98-by-spa-dauk | Here\'s the intuition:\n\nWe should use each same-character pair in s in building the longest palindrome. In addition, we can also use any one single character | Spaulding_ | NORMAL | 2024-06-04T00:50:09.225140+00:00 | 2024-06-04T21:03:05.158504+00:00 | 175 | false | Here\'s the intuition:\n\nWe should use each same-character pair in `s` in building the longest palindrome. In addition, we can also use any one single character left after the pairs are used.\n\nHere\'s the plan:\n- We apply `Counter` to `s` and use `values()` to determine the counts of the distinct characters.\n\n- ... | 9 | 0 | ['Python', 'Python3'] | 0 |
longest-palindrome | 📌📌Python3 || ⚡simple solution uwu | python3-simple-solution-uwu-by-maary-5pyb | \n\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n char_count = {}\n for char in s:\n char_count[char] = char_count | maary_ | NORMAL | 2023-03-01T23:12:09.860861+00:00 | 2023-03-06T23:21:57.221944+00:00 | 2,325 | false | \n```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n char_count = {}\n for char in s:\n char_count[char] = char_count.get(char, 0) + 1\n \n odd_count = 0\n for count in char_count.values():\n if count % 2 == 1:\n odd_count += 1... | 9 | 0 | ['Python3'] | 0 |
longest-palindrome | O(n) Time Complexity Java Solution with Algo | HashMap | on-time-complexity-java-solution-with-al-wlu1 | Algorithm\n Create a HashMap and add character if not present. If present then remove it from map.\n If there is no element left in map, then complete s can be | savan07 | NORMAL | 2022-05-13T09:41:53.380933+00:00 | 2022-05-13T09:41:53.380965+00:00 | 640 | false | **Algorithm**\n* Create a HashMap and add character if not present. If present then remove it from map.\n* If there is no element left in map, then complete s can be modified as a palindrome. So return length of s.\n* If there\'s some element left in map, then leaving one element which can be in centre of palindrome nu... | 9 | 0 | ['Java'] | 0 |
longest-palindrome | Kotlin - pure functional | kotlin-pure-functional-by-tucux-fo23 | \nclass Solution {\n fun longestPalindrome(s: String): Int {\n return minOf(\n s.length,\n 1 + s\n .groupingBy { | tucux | NORMAL | 2022-04-30T21:17:00.221439+00:00 | 2022-04-30T21:17:00.221473+00:00 | 486 | false | ```\nclass Solution {\n fun longestPalindrome(s: String): Int {\n return minOf(\n s.length,\n 1 + s\n .groupingBy { it }\n .eachCount()\n .map { (k, v) -> v / 2 * 2 }\n .sum()\n )\n }\n}\n``` | 9 | 0 | ['Kotlin'] | 0 |
longest-palindrome | C# | c-by-mhorskaya-m124 | \npublic int LongestPalindrome(string s) {\n\tvar result = s.GroupBy(c => c).Sum(g => g.Count() / 2 * 2);\n\treturn result == s.Length ? result : result + 1;\n} | mhorskaya | NORMAL | 2021-12-05T19:32:39.323254+00:00 | 2021-12-05T19:32:39.323282+00:00 | 590 | false | ```\npublic int LongestPalindrome(string s) {\n\tvar result = s.GroupBy(c => c).Sum(g => g.Count() / 2 * 2);\n\treturn result == s.Length ? result : result + 1;\n}\n``` | 9 | 0 | [] | 1 |
longest-palindrome | [Go] simple solution using map | go-simple-solution-using-map-by-nightybe-xiy5 | my solution using map.\n\ngo\nfunc longestPalindrome(s string) int {\n count := make(map[byte]int)\n for i:=0; i<len(s);i++{\n ch := s[i]\n | nightybear | NORMAL | 2020-08-15T02:31:17.952785+00:00 | 2020-08-15T02:31:17.952835+00:00 | 765 | false | my solution using map.\n\n```go\nfunc longestPalindrome(s string) int {\n count := make(map[byte]int)\n for i:=0; i<len(s);i++{\n ch := s[i]\n if _, ok := count[ch]; !ok {\n count[ch] = 1\n } else {\n count[ch] += 1\n }\n }\n \n ans := 0\n for _, val :... | 9 | 0 | ['Hash Table', 'Go'] | 3 |
longest-palindrome | [Java] Simple O(n) time solution with O(alphabetSize) space | java-simple-on-time-solution-with-oalpha-1j1r | \nclass Solution {\n public int longestPalindrome(String s) {\n int[] counts = new int[52];\n \n for (int i = 0; i < s.length(); i++) {\ | roka | NORMAL | 2020-08-14T07:14:02.506626+00:00 | 2020-08-14T07:24:15.033156+00:00 | 183 | false | ```\nclass Solution {\n public int longestPalindrome(String s) {\n int[] counts = new int[52];\n \n for (int i = 0; i < s.length(); i++) {\n char cur = s.charAt(i);\n int index = cur <= \'Z\' ? cur - \'A\' : cur - \'a\' + 26;\n counts[index]++;\n }\n\n ... | 9 | 0 | [] | 1 |
longest-palindrome | C++ beats 100% | c-beats-100-by-deleted_user-99mn | C++ beats 100%\n\n\n\n# Code\n\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n vector<int>lower(26,0);\n vector<int>upper(26,0 | deleted_user | NORMAL | 2024-06-04T01:02:00.444297+00:00 | 2024-06-04T01:02:00.444316+00:00 | 606 | false | C++ beats 100%\n\n\n\n# Code\n```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n vector<int>lower(26,0);\n vector<int>upper(26,0);\n for(int i=0;i<s.size();i++){\n ... | 8 | 0 | ['C++'] | 0 |
longest-palindrome | 💯✅🔥Easy Java ,Python3 ,C++ Solution|| 3 ms ||≧◠‿◠≦✌ | easy-java-python3-c-solution-3-ms-_-by-s-tyew | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is to find the length of the longest palindromic substring in a given strin | suyalneeraj09 | NORMAL | 2024-06-04T00:28:23.903153+00:00 | 2024-06-04T00:28:52.020902+00:00 | 1,384 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is to find the length of the longest palindromic substring in a given string. A palindromic substring is a substring that reads the same backward as forward. For example, "aba" is a palindromic substring of "ababa".\n# Approac... | 8 | 2 | ['String', 'Greedy', 'C++', 'Java', 'Python3'] | 5 |
longest-palindrome | Python simple kraken ninja covid version | python-simple-kraken-ninja-covid-version-nxzh | Intuition\n\nPalindromes are made up of pairs of matching characters, with an optional unmatched character in the center of the palindome (e.g. abba or abcba).\ | jmcmahon | NORMAL | 2023-01-16T01:00:53.523440+00:00 | 2023-01-16T01:00:53.523482+00:00 | 3,019 | false | # Intuition\n\nPalindromes are made up of pairs of matching characters, with an optional unmatched character in the center of the palindome (e.g. abba or abcba).\n\n# Approach\n\nUse a set to keep track of unmatched characters. If we encounter a character that is already in our set, we can add this pair to our palindro... | 8 | 0 | ['Python3'] | 3 |
longest-palindrome | Easy to Understand || Clean Solution || Fully Explained || O(n) || Java😊 | easy-to-understand-clean-solution-fully-yn96y | Request \uD83D\uDE0A:\n\nIf you find these solutions easy to understand and helpful, then\nPlease Upvote\uD83D\uDC4D\uD83D\uDC4D.\n\n\n# Code (Explained in comm | N7_BLACKHAT | NORMAL | 2022-12-29T06:13:13.669929+00:00 | 2022-12-29T06:13:13.669981+00:00 | 1,190 | false | # Request \uD83D\uDE0A:\n```\nIf you find these solutions easy to understand and helpful, then\nPlease Upvote\uD83D\uDC4D\uD83D\uDC4D.\n```\n\n# Code (Explained in comments) :\n```\nclass Solution \n{\n public int longestPalindrome(String s) \n {\n int count=0;\n HashSet<Character> data=new HashSet<... | 8 | 0 | ['Hash Table', 'String', 'Greedy', 'Java'] | 0 |
longest-palindrome | JavaScript simple hashmap O(n) solution | javascript-simple-hashmap-on-solution-by-m3c2 | ```\nvar longestPalindrome = function(s) {\n var map = {};\n var result = 0;\n for(let i = 0; i < s.length; i++){\n if(map[s[i]] === undefined){ | jiakang | NORMAL | 2017-12-02T00:09:49.301000+00:00 | 2017-12-02T00:09:49.301000+00:00 | 1,025 | false | ```\nvar longestPalindrome = function(s) {\n var map = {};\n var result = 0;\n for(let i = 0; i < s.length; i++){\n if(map[s[i]] === undefined){\n map[s[i]] = 1;\n }\n else if(map[s[i]] === 1){\n map[s[i]] = undefined;\n result += 2;\n }\n }\n ... | 8 | 0 | [] | 1 |
longest-palindrome | Java beats 100% | java-beats-100-by-deleted_user-fmmj | Java beats 100%\n\n\n\n# Code\n\nclass Solution {\n public int longestPalindrome(String s) {\n int[] array = new int[58];\n int count = 0,odd = | deleted_user | NORMAL | 2024-06-04T01:00:07.166596+00:00 | 2024-06-04T01:00:07.166614+00:00 | 1,097 | false | Java beats 100%\n\n\n\n# Code\n```\nclass Solution {\n public int longestPalindrome(String s) {\n int[] array = new int[58];\n int count = 0,odd = 0;\n\n for(char each : s.toCharArra... | 7 | 0 | ['Java'] | 0 |
longest-palindrome | 2 ways | hashSet | Freq Arrays | JAVA | 2-ways-hashset-freq-arrays-java-by-rohin-l88k | 1 - using HashSet\n\t\t\t\n\t\t\tclass Solution {\n\t\t\t\tpublic int longestPalindrome(String s) {\n\t\t\t\t\tif(s==null || s.length()==0) return 0;\n\t\t\t\t\ | RohiniK98 | NORMAL | 2022-10-16T05:31:21.379738+00:00 | 2022-10-16T05:31:21.379786+00:00 | 1,086 | false | **1 - using HashSet**\n\t\t\t\n\t\t\tclass Solution {\n\t\t\t\tpublic int longestPalindrome(String s) {\n\t\t\t\t\tif(s==null || s.length()==0) return 0;\n\t\t\t\t\tHashSet<Character> hs = new HashSet<Character>();\n\t\t\t\t\tint count = 0;\n\t\t\t\t\tfor(int i=0; i<s.length(); i++){\n\t\t\t\t\t\tif(hs.contains(s.charA... | 7 | 0 | ['Java'] | 0 |
longest-palindrome | Simple Java Solution Using HashMap & Value Count with Comments | simple-java-solution-using-hashmap-value-006j | \nclass Solution {\n public int longestPalindrome(String s) {\n HashMap<Character,Integer> map = new HashMap<>();\n int n=s.length();\n | imsanjaybisht | NORMAL | 2022-10-09T14:58:19.844480+00:00 | 2022-10-11T09:35:16.793193+00:00 | 1,644 | false | ```\nclass Solution {\n public int longestPalindrome(String s) {\n HashMap<Character,Integer> map = new HashMap<>();\n int n=s.length();\n for(int i=0;i<n;i++){\n map.put(s.charAt(i),map.getOrDefault(s.charAt(i),0)+1);\n }\n\t\t//First of all put all the elements in the HashMap... | 7 | 0 | ['Java'] | 1 |
longest-palindrome | Greedy approach | O(n) | Explained | greedy-approach-on-explained-by-nadaralp-wmgp | Explanation\nLet\'s first understand what a palindrome is: a palindrome is a word that, if we read it from left to right, and from right to left, it will read t | nadaralp | NORMAL | 2022-06-16T12:36:49.669242+00:00 | 2022-06-16T12:41:54.407197+00:00 | 754 | false | # Explanation\nLet\'s first understand what a palindrome is: a palindrome is a word that, if we read it from left to right, and from right to left, it will read the same. Examples are "madam" and "level".\n\nThe problem says we should return the length of the palindrome that **can be built** from a given string `s`. We... | 7 | 0 | ['Greedy', 'Python'] | 1 |
longest-palindrome | Simple Java solution with a set(NOT A MAP) and 10-lines code, easy understand | simple-java-solution-with-a-setnot-a-map-d4gq | Noticed the unit of constructing palindrome is pair of char. So we don\'t need to count Characters but just make a minus. \nRefer to this code, it\'s self-expla | paladintyrion | NORMAL | 2021-03-21T20:37:36.652632+00:00 | 2021-03-21T20:38:42.018156+00:00 | 415 | false | Noticed the unit of constructing palindrome is pair of char. So we don\'t need to count Characters but just make a minus. \nRefer to this code, it\'s self-explanatory.\n\n```\npublic int longestPalindrome(String s) {\n\tSet<Character> set = new HashSet<>();\n\tfor (char c : s.toCharArray()) {\n\t\tif (set.contains(c)) ... | 7 | 0 | ['Java'] | 3 |
longest-palindrome | C++ | c-by-testrun260-5p55 | \nclass Solution {\npublic:\n int longestPalindrome(string s) {\n unordered_map<char,int>freq;\n int res = 0;\n int oddCount = 0;\n | testrun260 | NORMAL | 2020-08-15T02:02:10.783754+00:00 | 2020-08-15T02:02:10.783786+00:00 | 393 | false | ```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n unordered_map<char,int>freq;\n int res = 0;\n int oddCount = 0;\n for(int i = 0; i < s.length(); ++i){\n freq[s[i]]++;\n }\n /*\n two cases:\n if current counter is even... | 7 | 0 | ['C'] | 0 |
longest-palindrome | 💯💯Easiest solution || 🔥🔥Without any Data Structure 🔥🔥|| Count Frequency || Easy to Understand | easiest-solution-without-any-data-struct-vxy0 | \n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\n public int longestPalindrome(String s) {\n boole | darshan_anghan | NORMAL | 2024-06-04T05:27:27.630326+00:00 | 2024-06-04T05:27:27.630345+00:00 | 808 | false | \n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public int longestPalindrome(String s) {\n boolean[] arr = new boolean[123]; // a-z ASCII value is 65 to 90 && A-Z ASCII value is 97 to 122\n int i = 0;\n int ans = 0;\n while(i<s.le... | 6 | 0 | ['Java'] | 3 |
longest-palindrome | Easy and Simple Solution | Python | easy-and-simple-solution-python-by-kg-pr-k4z6 | Intuition\nTo solve the problem of finding the length of the longest palindrome that can be built from the given string, we need to understand the properties of | KG-Profile | NORMAL | 2024-06-04T04:46:05.679165+00:00 | 2024-06-04T04:46:05.679191+00:00 | 433 | false | # Intuition\nTo solve the problem of finding the length of the longest palindrome that can be built from the given string, we need to understand the properties of palindromes. A palindrome reads the same forward and backward. Here\u2019s the plan:\n\n1. **Count Character Frequencies:** First, we count the frequency of ... | 6 | 0 | ['Python3'] | 1 |
longest-palindrome | Simple Intutive Solution with explanation | clean code [c++/go] | simple-intutive-solution-with-explanatio-pk5a | Intuition\n- We can count pairs to get our result. Count all pairs pairs and we can form string of length pairs*2 + 1\n- If summing up pairs does not equals to | anupsingh556 | NORMAL | 2024-06-04T01:55:14.382680+00:00 | 2024-06-04T01:55:14.382696+00:00 | 1,551 | false | # Intuition\n- We can count pairs to get our result. Count all pairs `pairs` and we can form string of length `pairs*2 + 1`\n- If summing up pairs does not equals to lenght of string it means there is atleast one character without pair we can use that in pallindrome as well\n<!-- Describe your first thoughts on how to ... | 6 | 0 | ['C++', 'Go'] | 5 |
longest-palindrome | 2 Easy Interview Approaches ✅ || using HashMap🔥 || without Hasmap💯 || All Language Solution💯 | 2-easy-interview-approaches-using-hashma-li3d | \n\n# Approach - 1\n Describe your approach to solving the problem. \nUsing map - to store the frequency of the characters\n\n# Complexity\n- Time complexity: O | naman_malik | NORMAL | 2024-06-04T01:09:18.899807+00:00 | 2024-06-04T01:09:18.899824+00:00 | 2,124 | false | \n\n# Approach - 1\n<!-- Describe your approach to solving the problem. -->\nUsing map - to store the frequency of the characters\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time compl... | 6 | 1 | ['Hash Table', 'String', 'Ordered Map', 'Swift', 'Python', 'C++', 'Java'] | 3 |
longest-palindrome | ⚡️Easy Python 3 | Greedy Solution ⚡️O(n) | beats 85% | 64ms 🔥 | easy-python-3-greedy-solution-on-beats-8-3439 | Intuition\n\nPalindrome is - a word that reads the same when read from left to right and from right to left. It explains that the task is to determine the lengt | nicolalino | NORMAL | 2023-05-03T15:52:31.587152+00:00 | 2023-05-03T15:52:31.587199+00:00 | 2,066 | false | # Intuition\n\nPalindrome is - a word that reads the same when read from **left** to **right** and from right to left. It explains that the task is to determine the length of a palindrome that can be formed using a given string. The approach taken is to build the palindrome rather than searching for it. The passage not... | 6 | 0 | ['Greedy', 'Python', 'Python3'] | 0 |
longest-palindrome | C++ || 2 DIFFIERENT APPROACHS || ARRAY AND HASHMAP || EASY | c-2-diffierent-approachs-array-and-hashm-7jno | --->Here\'s a step-by-step explanation of the code:\n\n1-The program starts by defining a function longestPalindrome that takes a string s as input and return | Ayush00001 | NORMAL | 2023-04-04T16:51:00.084285+00:00 | 2023-04-14T06:13:30.109868+00:00 | 2,015 | false | --->Here\'s a step-by-step explanation of the code:\n\n1-The program starts by defining a function longestPalindrome that takes a string s as input and returns an integer.\n\n2-It first checks if the length of the string is 1. If it is, then it returns 1 because a palindrome of length 1 can be formed using a single c... | 6 | 0 | ['C++'] | 3 |
longest-palindrome | ✅ Everything explained using comment | Easy Approach | everything-explained-using-comment-easy-63nc6 | \n// C++ Solution:\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n \n unordered_map<int,int> mp;\n int res = 0;\n | Sayakmondal | NORMAL | 2022-08-16T17:50:50.386797+00:00 | 2022-08-18T05:07:38.310063+00:00 | 569 | false | ```\n// C++ Solution:\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n \n unordered_map<int,int> mp;\n int res = 0;\n for(int i = 0; i < s.length(); i++) {\n mp[s[i]]++;\n // if a particular character occurs in even we can definitely take it and place... | 6 | 0 | ['C', 'C++'] | 1 |
longest-palindrome | Javascript, oddCount | javascript-oddcount-by-fbecker11-hqbz | \nvar longestPalindrome = function(s) {\n const map = new Map()\n for(const c of s){\n map.set(c, (map.get(c) || 0) + 1)\n }\n let count = 0\n let oddCo | fbecker11 | NORMAL | 2022-06-24T14:09:42.540410+00:00 | 2022-06-24T14:09:42.540448+00:00 | 768 | false | ```\nvar longestPalindrome = function(s) {\n const map = new Map()\n for(const c of s){\n map.set(c, (map.get(c) || 0) + 1)\n }\n let count = 0\n let oddCount = 0\n for(const [k, v] of map){\n if(v % 2 === 0){\n count+=v\n }else{\n count+=v\n oddCount++\n }\n }\n\n return oddCount ? c... | 6 | 0 | ['JavaScript'] | 2 |
longest-palindrome | 0 ms, faster than 100.00% of C++ online submissions | 0-ms-faster-than-10000-of-c-online-submi-va07 | \nclass Solution {\npublic:\n int longestPalindrome(string s) {\n int len=1;\n unordered_map<char,int>mp;\n for(auto c:s){\n | Troy_01 | NORMAL | 2021-12-22T13:26:19.536747+00:00 | 2021-12-22T13:26:19.536784+00:00 | 553 | false | ```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n int len=1;\n unordered_map<char,int>mp;\n for(auto c:s){\n mp[c]++;\n }\n for(auto x:mp){\n if(x.second>=2){\n if(x.second%2==0)len+=x.second;\n else len+=x.seco... | 6 | 0 | ['C'] | 0 |
longest-palindrome | C++ straight forward solution faster than 100% | c-straight-forward-solution-faster-than-q1bxi | Logic:\nAny character with even frequency could be included in palindrome.\ni.e. AAaaBBbb --> AaBbbBaA\nIn addition, character with odd frequency could be inc | AyushMistry | NORMAL | 2021-11-05T18:23:21.789086+00:00 | 2021-11-05T18:25:22.818253+00:00 | 249 | false | **Logic:**\nAny character with even frequency could be included in palindrome.\ni.e. AAaaBBbb --> AaBbbBaA\nIn addition, character with odd frequency could be included by ignoring it\'s one apperance and one char with odd frequency. \ni.e. AAaaBBbbcccd --> AaBbcccbBaA (OR) AaBbcdcbBaA\n\n**Approach:**\nCalculate fre... | 6 | 0 | [] | 3 |
longest-palindrome | Python O(n) time using hashmap with explanation | python-on-time-using-hashmap-with-explan-neut | Essentially we want to counting pairs, plus one if there is another non-pair character aka\nlongestPlindrome = 2*numPairs + 1 if 2*numPairs < len(s) (the extra | algorithm_cat | NORMAL | 2020-08-15T06:40:20.560556+00:00 | 2020-08-15T06:40:20.560603+00:00 | 192 | false | Essentially we want to counting pairs, plus one if there is another non-pair character aka\n`longestPlindrome = 2*numPairs + 1 if 2*numPairs < len(s)` (the extra 1 is because a single character can go in the middle)\nWe have two options:\n1. sort with potentially no extra space but `O(nlogn)` time\n2. use a hashmap -> ... | 6 | 0 | [] | 0 |
longest-palindrome | simple python solution with hash table | simple-python-solution-with-hash-table-b-ru5a | \nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n s_dict, l, flag = dict(), len(s), False\n for c in s:\n s_dict[c] | dobuzi | NORMAL | 2020-08-15T01:41:27.502230+00:00 | 2020-08-15T01:41:27.502260+00:00 | 129 | false | ```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n s_dict, l, flag = dict(), len(s), False\n for c in s:\n s_dict[c] = s_dict.get(c, 0) + 1\n for v in s_dict.values():\n if v%2 == 1:\n l -= 1\n flag = True\n return l + ... | 6 | 0 | [] | 0 |
longest-palindrome | [java] Simple solution, faster than 100% | java-simple-solution-faster-than-100-by-qfu1a | \nclass Solution {\n public int longestPalindrome(String s) {\n boolean[] seen = new boolean[58];\n int len = 0; \n int singles = 0; | deriso | NORMAL | 2020-08-15T00:26:07.197371+00:00 | 2020-08-15T00:26:07.197402+00:00 | 116 | false | ```\nclass Solution {\n public int longestPalindrome(String s) {\n boolean[] seen = new boolean[58];\n int len = 0; \n int singles = 0;\n \n for (char c : s.toCharArray()) {\n int index = c - \'A\';\n if (seen[index]) {\n seen[index] = false... | 6 | 0 | [] | 0 |
longest-palindrome | Simple fast Java solution | simple-fast-java-solution-by-jono_m-tmav | \n public int longestPalindrome(String s) {\n int [] chars = new int[128];\n int len = s.length();\n \tfor(char ch : s.toCharArray()) {\n | jono_m | NORMAL | 2020-08-14T09:49:21.358579+00:00 | 2020-08-20T11:34:34.317663+00:00 | 602 | false | ```\n public int longestPalindrome(String s) {\n int [] chars = new int[128];\n int len = s.length();\n \tfor(char ch : s.toCharArray()) {\n \t\tchars[ch - \'A\'] ^= ch;\n \t\tlen = len + (chars[ch - \'A\'] == 0 ? 1 : -1);\n \t}\n \treturn len == s.length() ? len : len + 1;\n }\n``` | 6 | 0 | ['Java'] | 1 |
longest-palindrome | 1ms Java Solution with Test Case | 1ms-java-solution-with-test-case-by-shaw-zyl5 | \nclass Solution {\n // ""\n // "AaAa"\n // "aaa"\n // "aaaa"\n // "AAA"\n // "AAAA"\n // "AacAaa"\n // Time: O(n)\n // Space: O(1)\n | shawnngo | NORMAL | 2019-10-01T23:44:44.919397+00:00 | 2019-10-01T23:44:44.919463+00:00 | 271 | false | ```\nclass Solution {\n // ""\n // "AaAa"\n // "aaa"\n // "aaaa"\n // "AAA"\n // "AAAA"\n // "AacAaa"\n // Time: O(n)\n // Space: O(1)\n public int longestPalindrome(String s) {\n if (s == null) return 0;\n \n int[] count = new int[128];\n for (char c : s.toChar... | 6 | 0 | [] | 0 |
longest-palindrome | 100% Beats Java Solution , Bitwise Approach to Maximize Palindrome Length in Linear Time🔥. | 100-beats-java-solution-bitwise-approach-uur3 | Intuition\nUse a bitmask to track character frequencies. Each character toggles a specific bit; 1 means odd frequency, 0 means even. Count the 1s to get the odd | deepu_01 | NORMAL | 2024-11-06T09:47:56.697344+00:00 | 2024-11-06T12:52:09.593578+00:00 | 231 | false | # Intuition\nUse a bitmask to **track character frequencies**. Each character toggles a specific bit; 1 means odd frequency, 0 means even. Count the 1s to get the odd-frequency characters. Max palindrome length is **n - (odd_count - 1).**\n\n# Complexity\n- Time complexity: **O(n)**\n\n- Space complexity: **O(1)**\n\n#... | 5 | 0 | ['Bit Manipulation', 'Bitmask', 'Java'] | 1 |
longest-palindrome | C++ easy and simple solution without using Hashmap and beats 100% | c-easy-and-simple-solution-without-using-yyrk | Intuition\nkeep record of occurances of each character\n# Approach\n1. Every even lenght palindrome have even no of occurances of characters so for even occuran | sahil_singh10 | NORMAL | 2024-06-04T15:49:38.725561+00:00 | 2024-06-04T15:49:38.725594+00:00 | 230 | false | # Intuition\nkeep record of occurances of each character\n# Approach\n1. Every even lenght palindrome have even no of occurances of characters so for even occurance we add occurance to the lenght as it is.\n2. Every odd length palindrome should have only one odd occurance so if the lenght of string is more than usual t... | 5 | 0 | ['String', 'C++'] | 0 |
longest-palindrome | ✅ One Line Solution | one-line-solution-by-mikposp-niam | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: O(n). Space complexi | MikPosp | NORMAL | 2024-06-04T08:04:40.855200+00:00 | 2024-06-04T08:13:52.984578+00:00 | 1,068 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: $$O(n)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> int:\n return min(sum(v&~1 for v in Counter(s).values())+1,len(s))\n`... | 5 | 0 | ['Hash Table', 'String', 'Python', 'Python3'] | 0 |
longest-palindrome | Fast and Easy solution by using frequency of characters concept | HashMap |C++ and Java solution 💯✅ | fast-and-easy-solution-by-using-frequenc-2chh | Intuition \uD83E\uDDE0\n Describe your first thoughts on how to solve this problem. \nWe need to have store frequency of each character to check whether it is o | purnimakesarwani47 | NORMAL | 2024-06-04T05:22:18.228582+00:00 | 2024-06-04T05:22:18.228640+00:00 | 709 | false | # Intuition \uD83E\uDDE0\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to have store frequency of each character to check whether it is odd or even.\n\n---\n\n\n# Approach \uD83E\uDE9C\n<!-- Describe your approach to solving the problem. -->\n1. Make a map which will store the frequency ... | 5 | 0 | ['Hash Table', 'String', 'C++', 'Java'] | 1 |
longest-palindrome | C# Solution for Longest Palindrome Problem | c-solution-for-longest-palindrome-proble-j48z | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind this solution is similar to the previous one but uses an array ins | Aman_Raj_Sinha | NORMAL | 2024-06-04T03:14:55.567270+00:00 | 2024-06-04T03:14:55.567290+00:00 | 932 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this solution is similar to the previous one but uses an array instead of a HashMap to count character frequencies. This leverages the fact that we are dealing with a fixed set of characters (ASCII values for lowercas... | 5 | 0 | ['C#'] | 0 |
longest-palindrome | C++ || Hashmap || Simple + Optimal || 0 ms || Beats 100% | c-hashmap-simple-optimal-0-ms-beats-100-6c4w4 | \n# Code\n\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n unordered_map<char, int> mp;\n for(auto i : s) {\n mp[i] | meurudesu | NORMAL | 2024-02-10T06:22:12.522698+00:00 | 2024-02-10T06:22:12.522726+00:00 | 596 | false | \n# Code\n```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n unordered_map<char, int> mp;\n for(auto i : s) {\n mp[i]++;\n }\n int ans = 0;\n bool isOddPresent = false;\n for(auto i : mp) {\n if(i.second % 2 == 0) ans += i.second;\n ... | 5 | 0 | ['Hash Table', 'String', 'Greedy', 'C++'] | 0 |
longest-palindrome | C++ || beginner Friendly || Map | c-beginner-friendly-map-by-inam_28_06-37mq | Method \nusing hash map\nTime Complexity-O(n)\n\n\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n map<char,int>mp;\n int ans=0 | Inam_28_06 | NORMAL | 2023-08-22T03:29:07.824916+00:00 | 2023-08-22T03:29:07.824940+00:00 | 300 | false | Method \nusing hash map\nTime Complexity-O(n)\n\n```\nclass Solution {\npublic:\n int longestPalindrome(string s) {\n map<char,int>mp;\n int ans=0;\n for(int i=0;i<s.size();i++){\n ... | 5 | 0 | ['C'] | 1 |
longest-palindrome | Easiest Solution || 96% Beats || JavaScript || o(n) | easiest-solution-96-beats-javascript-on-oxp6o | 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 | ayesha_naeem | NORMAL | 2023-08-08T10:52:54.824308+00:00 | 2023-08-08T10:52:54.824334+00:00 | 683 | 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 | ['Hash Table', 'JavaScript'] | 0 |
longest-palindrome | python3 easy to understand solution 98.12% beats with froop | python3-easy-to-understand-solution-9812-gd9j | 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 | ayan_101 | NORMAL | 2023-08-02T02:00:16.288802+00:00 | 2023-08-02T02:00:16.288830+00:00 | 467 | 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 | ['Python3'] | 0 |
longest-palindrome | simple 100% , one loop | simple-100-one-loop-by-adwxsghu-h47b | 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 | adwxsghu | NORMAL | 2023-07-13T10:01:14.421193+00:00 | 2023-07-13T10:01:14.421217+00:00 | 116 | 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 | ['Go'] | 1 |
longest-palindrome | Java solution using HashMap, 9ms | java-solution-using-hashmap-9ms-by-knick-gg07 | \n# Code\n\nclass Solution {\n public int longestPalindrome(String s) {\n int odd_count = 0;\n HashMap<Character, Integer> map = new HashMap<>( | Knickon | NORMAL | 2023-03-16T15:19:28.997289+00:00 | 2023-03-16T15:19:28.997318+00:00 | 2,421 | false | \n# Code\n```\nclass Solution {\n public int longestPalindrome(String s) {\n int odd_count = 0;\n HashMap<Character, Integer> map = new HashMap<>();\n for (char ch: s.toCharArray()){\n map.put(ch, map.getOrDefault(ch, 0) + 1);\n if (map.get(ch) % 2 == 1){\n o... | 5 | 0 | ['Hash Table', 'Java'] | 1 |
longest-palindrome | 🚀 100% faster approach, Using Hash Table, BRUTE FORCE | 100-faster-approach-using-hash-table-bru-nw4l | Intuition\n Describe your first thoughts on how to solve this problem. \nIf you see examples, and do a dry run, for each random string, you might see a pattern, | programmer-buddy | NORMAL | 2023-03-07T08:02:51.733481+00:00 | 2023-03-07T08:18:10.529463+00:00 | 1,663 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf you see examples, and do a dry run, for each random string, you might see a pattern, which is:\nWhen we have to create a palindrome string, we need **EVEN NUMBER OF CHARACTERS + 1**, so for that, if we just count each character frequen... | 5 | 0 | ['Hash Table', 'Greedy', 'C++'] | 2 |
longest-palindrome | Java || 100ms || Easy Approach | java-100ms-easy-approach-by-naveen_kumar-dkuu | \n\n# Approach\n Describe your approach to solving the problem. \n We have to calculate the maximum pair possible from every character.\n Store the occurence of | Naveen_kumar__ | NORMAL | 2023-02-18T14:45:54.399970+00:00 | 2023-02-18T14:45:54.400020+00:00 | 1,290 | false | \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* We have to calculate the maximum pair possible from every character.\n* Store the occurence of every character in count array.\n* Then iterate over count array, and let occurence of character is n then do,\n* if n is even then add n. (i.e let n ... | 5 | 0 | ['Java'] | 2 |
longest-palindrome | C++ solution using hashmap with complete explanation|| Easy to understand | c-solution-using-hashmap-with-complete-e-1qoi | Intuition\nIn palindrome string either all characters occurs even number of times or only one character occurs once and rest occurs even number of times.\n\nTo | jainarihant195 | NORMAL | 2023-01-14T09:09:42.818789+00:00 | 2023-01-14T09:11:01.052275+00:00 | 663 | false | ## Intuition\nIn palindrome string either all characters occurs **even** number of times or only **one** character occurs once and rest occurs even number of times.\n\nTo understand it better : In "abccba" all characters are occuring twice and it is palindrome and in "abcdcba" all characters are occuring twice except ... | 5 | 0 | ['Hash Table', 'String', 'C', 'C++'] | 2 |
longest-palindrome | [Ruby] 1-liner, Bit Magic | ruby-1-liner-bit-magic-by-0x81-vthz | ruby\ndef longest_palindrome(s) =\n [s.size, s.each_char.tally.sum { _2 & ~1 } + 1].min\n\nruby\ndef longest_palindrome(s) =\n s.each_char.tally.reduce(0) | 0x81 | NORMAL | 2023-01-04T16:12:17.755143+00:00 | 2023-01-05T06:13:34.560569+00:00 | 162 | false | ```ruby\ndef longest_palindrome(s) =\n [s.size, s.each_char.tally.sum { _2 & ~1 } + 1].min\n```\n```ruby\ndef longest_palindrome(s) =\n s.each_char.tally.reduce(0) do | r, (_, v) |\n r + (v & ~1) | v & 1\n end\n``` | 5 | 0 | ['Ruby'] | 3 |
longest-palindrome | Python3 O(n) using dict | python3-on-using-dict-by-dhuang1993-1hqh | \ndef longestPalindrome(s):\n letters = {}\n \n max = 0\n for c in s:\n if c in letters:\n letters.pop(c)\ | dhuang1993 | NORMAL | 2022-11-08T00:35:51.581051+00:00 | 2022-11-08T00:35:51.581088+00:00 | 611 | false | ```\ndef longestPalindrome(s):\n letters = {}\n \n max = 0\n for c in s:\n if c in letters:\n letters.pop(c)\n max += 2\n else:\n letters[c] = 1\n \n if letters:\n max += 1\n \n return m... | 5 | 0 | [] | 3 |
final-array-state-after-k-multiplication-operations-i | Greedy make_heap vs priority_queue||beats 100% | greedy-make_heap-vs-priority_queuebeats-ypx3x | IntuitionIt's again a question about Greedy using heap/pq.Implement in both in C++ code. Python code uses heapq.heapify.Approach
1st appraoch uses make_heap; it | anwendeng | NORMAL | 2024-12-16T00:30:23.231071+00:00 | 2024-12-16T01:15:37.498045+00:00 | 8,554 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt\'s again a question about Greedy using heap/pq.\n\nImplement in both in C++ code. Python code uses heapq.heapify.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. 1st appraoch uses `make_heap`; it constructs a v... | 27 | 0 | ['Array', 'Heap (Priority Queue)', 'Simulation', 'C++', 'Python3'] | 8 |
final-array-state-after-k-multiplication-operations-i | O(N*N)->O(K*log(N)) Video Solution 🔥 || How to 🤔 in Interview || Priority_queue | onn-oklogn-video-solution-how-to-in-inte-8mvu | If you like the solution Please Upvote and subscribe to my youtube channel\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nDry Run | ayushnemmaniwar12 | NORMAL | 2024-08-25T06:52:13.215634+00:00 | 2024-08-25T07:16:37.463791+00:00 | 3,690 | false | ***If you like the solution Please Upvote and subscribe to my youtube channel***\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDry Run few examples and observe how you can optimize further\n\n\n\n***Easy Video Explanation***\n\nhttps://youtu.be/YxRD34k_Oog\n\n# Brute Force\n\n\n``... | 24 | 2 | ['Heap (Priority Queue)', 'C++', 'Java', 'Python3'] | 7 |
final-array-state-after-k-multiplication-operations-i | Python 3 || 8 lines, heap || T/S: 95% / 21% | python-3-8-lines-heap-ts-95-21-by-spauld-of24 | \npython3 []\nclass Solution:\n def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]:\n\n heap = list(zip(nums, range(len(nu | Spaulding_ | NORMAL | 2024-08-25T15:31:09.026284+00:00 | 2024-08-28T04:28:48.587009+00:00 | 622 | false | \n```python3 []\nclass Solution:\n def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]:\n\n heap = list(zip(nums, range(len(nums))))\n heapify(heap)\n\n while k:\n num, idx = heappop(heap)\n heappush(heap,(num * multiplier, idx))\n k-=1... | 16 | 0 | ['Python3'] | 2 |
final-array-state-after-k-multiplication-operations-i | Beat 100% | Solution for LeetCode#3264 | beat-100-solution-for-leetcode3264-by-sa-s7f2 | IntuitionThe problem requires finding the minimum element in the array, multiplying it by a given factor, and repeating this process k times. The intuition is t | samir023041 | NORMAL | 2024-12-16T00:39:28.494895+00:00 | 2024-12-16T00:39:28.494895+00:00 | 3,526 | false | \n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires finding the minimum element in the array, multiplying it by a given factor, and repeating this proc... | 12 | 0 | ['Heap (Priority Queue)', 'Java'] | 3 |
final-array-state-after-k-multiplication-operations-i | ✅Simple Solution | Beginner Friendly | Easy Approach with Explanation✅ | simple-solution-beginner-friendly-easy-a-vmqy | IntuitionThe problem requires modifying an array by iteratively finding and multiplying the minimum element. The key insight is to repeatedly identify the small | Jithinp96 | NORMAL | 2024-12-16T03:56:49.193533+00:00 | 2024-12-16T03:56:49.193533+00:00 | 1,686 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires modifying an array by iteratively finding and multiplying the minimum element. The key insight is to repeatedly identify the smallest element and transform it using a given multiplier for a specified number of iterati... | 10 | 0 | ['C', 'C++', 'TypeScript', 'JavaScript'] | 1 |
final-array-state-after-k-multiplication-operations-i | 💢☠💫Easiest👾💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅☠🔥 Beats 100 | easiestfaster-lesser-cpython3javacpython-vdz5 | Intuition
ApproachComplexity
Time complexity:
Space complexity:
Code | Edwards310 | NORMAL | 2024-08-25T11:45:02.020288+00:00 | 2024-12-16T14:37:25.718713+00:00 | 809 | false | # Intuition\n\n\n\n```javascript []\n//JavaScript Code\n/**\... | 9 | 1 | ['Array', 'String', 'C', 'Python', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'C#'] | 1 |
final-array-state-after-k-multiplication-operations-i | Python | Greedy Pattern | python-greedy-pattern-by-khosiyat-uapm | see the Successfully Accepted SubmissionCodeExplanationInitialization and Loop:
The function performs k operations.
For each operation, it identifies the minimu | Khosiyat | NORMAL | 2024-12-16T04:07:37.234474+00:00 | 2024-12-16T04:07:37.234474+00:00 | 397 | false | [see the Successfully Accepted Submission](https://leetcode.com/problems/final-array-state-after-k-multiplication-operations-i/submissions/1479879843/?envType=daily-question&envId=2024-12-16)\n\n# Code\n```python3 []\nfrom typing import List\n\nclass Solution:\n def getFinalState(self, nums: List[int], k: int, multi... | 8 | 0 | ['Python3'] | 0 |
final-array-state-after-k-multiplication-operations-i | EASIEST PYTHON CODE || BEATS 100% ✅ | easiest-python-code-beats-100-by-prathik-vea9 | IntuitionThe question was to find the minimum number and multiply it in-place for k times. So we need an iterative loop, find the minimum number & multiply it.A | PrathikRKrishnan | NORMAL | 2024-12-16T02:05:10.411999+00:00 | 2024-12-16T02:05:10.411999+00:00 | 1,004 | false | \n\n# Intuition\nThe question was to find the minimum number and multiply it in-place for k times. So we need an iterative loop, find the minimum number & multiply it.\n\n# Approach\nSo we first create a fo... | 8 | 0 | ['Python3'] | 1 |
final-array-state-after-k-multiplication-operations-i | 100% Beats 🚀 Beginner Detailed Solution 🧠 | 100-beats-beginner-detailed-solution-by-v7ylh | 🧠 IntuitionThe problem involves transforming an array by performing k operations, where the smallest element (breaking ties by index) is multiplied by a given m | Sumeet_Sharma-1 | NORMAL | 2024-12-16T01:41:35.288237+00:00 | 2024-12-16T01:41:35.288237+00:00 | 5,312 | false | # \uD83E\uDDE0 Intuition\n<!-- \uD83D\uDE80 Describe your first thoughts on how to solve this problem. -->\nThe problem involves transforming an array by performing `k` operations, where the smallest element (breaking ties by index) is multiplied by a given multiplier. To efficiently track the smallest element and its ... | 8 | 0 | ['Heap (Priority Queue)', 'C++', 'Java', 'Python3', 'Ruby', 'JavaScript', 'C#'] | 6 |
final-array-state-after-k-multiplication-operations-i | Easyyy Pessyyy Solution ✅| Beats 100 % Runtime 🔥 | Memory 97.81% 🔥 | easyyy-pessyyy-solution-beats-100-runtim-rs79 | IntuitionThe problem involves repeatedly modifying the smallest element in an array k times by multiplying it by a given multiplier. To achieve this:
Finding th | jaitaneja333 | NORMAL | 2024-12-16T05:48:37.160670+00:00 | 2024-12-16T05:48:37.160670+00:00 | 1,169 | false | \n\n# Intuition\nThe problem involves repeatedly modifying the smallest element in an array k times by multiplying it by a given multiplier. To achieve this:\n\n1. Finding the smallest element: At each step... | 7 | 0 | ['Array', 'Math', 'C++', 'Java'] | 2 |
final-array-state-after-k-multiplication-operations-i | Beats 100%✅✅|| Easy Priority Queue Solution | beats-100-easy-priority-queue-solution-b-kuui | IntuitionThe problem involves modifying the array nums iteratively based on certain conditions. Using a priority queue allows us to efficiently track the smalle | arunk_leetcode | NORMAL | 2024-12-16T04:26:50.484259+00:00 | 2024-12-16T04:26:50.484259+00:00 | 1,431 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves modifying the array `nums` iteratively based on certain conditions. Using a priority queue allows us to efficiently track the smallest element, which will help in making the modifications systematically.\n\n# Approach... | 7 | 0 | ['Two Pointers', 'Heap (Priority Queue)', 'C++'] | 1 |
final-array-state-after-k-multiplication-operations-i | [c++, Java] Using minHeap solution | using-priority-queue-by-kreakemp-fgyl | Approach :
Simply simulate what has been asked using a minHeap ( priority queue )
Code Here is an article of my last interview experience - A Journey to FAANG C | kreakEmp | NORMAL | 2024-08-25T04:42:33.861326+00:00 | 2024-12-16T07:13:17.274285+00:00 | 328 | false | # Approach : \n- Simply simulate what has been asked using a minHeap ( priority queue )\n\n# Code\n```cpp []\nvector<int> getFinalState(vector<int>& nums, int k, int multiplier) {\n priority_queue<pair<int,int>, vector<pair<int, int>>, greater<pair<int,int>>> pq;\n for(auto i = 0; i < nums.size(); ++i) pq.push({n... | 7 | 1 | ['C++'] | 1 |
final-array-state-after-k-multiplication-operations-i | C++ || O(k*n) || O(k*logN) | c-okn-oklogn-by-abhay5349singh-p8q6 | Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n get minimum value from array for each k\n update minimum value after mul | abhay5349singh | NORMAL | 2024-08-25T04:01:00.135379+00:00 | 2024-08-25T04:01:00.135410+00:00 | 815 | false | **Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* get minimum value from array for each k\n* update minimum value after multiplying\n\n```\nclass Solution {\npublic:\n vector<int> getFinalState(vector<int>& nums, int k, int mul) {\n while(k--){\n int m... | 7 | 3 | [] | 2 |
final-array-state-after-k-multiplication-operations-i | Python | Using built-in fuctions | Beats 98.84% | python-using-built-in-fuctions-beats-988-yicj | Complexity\n- Time complexity: O(n*k)\n\n- Space complexity: O(1)\n\n# Code\npython3 []\nclass Solution:\n def getFinalState(self, nums: List[int], k: int, m | vish501 | NORMAL | 2024-09-25T07:47:15.657388+00:00 | 2024-09-25T07:47:15.657418+00:00 | 81 | false | # Complexity\n- Time complexity: $$O(n*k)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```python3 []\nclass Solution:\n def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]:\n for _ in range(k):\n nums[nums.index(min(nums))] *= multiplier\n return nums\n``` | 5 | 0 | ['Array', 'Math', 'Python3'] | 1 |
final-array-state-after-k-multiplication-operations-i | Simple and Easy C++ Code || ☠️💯 | simple-and-easy-c-code-by-shodhan_ak-964n | \n# Code\ncpp []\nclass Solution {\npublic:\n vector<int> getFinalState(vector<int>& nums, int k, int multiplier) {\n while (k != 0) {\n au | Shodhan_ak | NORMAL | 2024-08-25T14:19:16.000718+00:00 | 2024-08-25T14:19:16.000790+00:00 | 632 | false | \n# Code\n```cpp []\nclass Solution {\npublic:\n vector<int> getFinalState(vector<int>& nums, int k, int multiplier) {\n while (k != 0) {\n auto it = min_element(nums.begin(), nums.end());\n *it *= multiplier;\n k--;\n }\n return nums;\n }\n};\n\n```\n# Intuit... | 5 | 0 | ['C++'] | 0 |
final-array-state-after-k-multiplication-operations-i | ✅100 % fastest ✅Detailed Explanation💯✅Easy And Simple Solution ✅Clean Code ✅ Beginner Friendly | 100-fastest-detailed-explanationeasy-and-u7pm | Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\nFoll | ayushluthra62 | NORMAL | 2024-08-25T04:00:41.813057+00:00 | 2024-08-25T04:00:41.813085+00:00 | 868 | false | ***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***<br>\n**Follow me on LinkeDin [[click Here](https://www.linkedin.com/in/ayushluthra62/)]**\n\n# Approach :\nApproach is very simple: we have to do k operations,... | 5 | 0 | ['Math', 'C++'] | 1 |
final-array-state-after-k-multiplication-operations-i | ✅ One Line Solution | one-line-solution-by-mikposp-2xtv | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)CodeTime complexity: O(n∗k). Space complexity: O(n). | MikPosp | NORMAL | 2024-12-16T10:06:07.998834+00:00 | 2024-12-16T10:06:07.998834+00:00 | 408 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code\nTime complexity: $$O(n*k)$$. Space complexity: $$O(n)$$.\n```python3\nclass Solution:\n def getFinalState(self, a: List[int], k: int, q: int) -> List[int]:\n return [setitem(a,a.index(m:=min... | 4 | 0 | ['Array', 'Simulation', 'Python', 'Python3'] | 1 |
final-array-state-after-k-multiplication-operations-i | C++ Solution || Detailed Explanation | c-solution-detailed-explanation-by-rohit-jjbo | IntuitionThe problem involves modifying elements in a vector based on their values and positions while maintaining an order of operations. Using a priority queu | Rohit_Raj01 | NORMAL | 2024-12-16T08:35:00.850492+00:00 | 2024-12-16T08:35:00.850492+00:00 | 178 | false | # Intuition\nThe problem involves modifying elements in a vector based on their values and positions while maintaining an order of operations. Using a **priority queue (min-heap)** is intuitive here because it allows us to efficiently fetch and update the smallest element at every step, which is critical given the natu... | 4 | 0 | ['Array', 'Math', 'Heap (Priority Queue)', 'Simulation', 'C++'] | 0 |
final-array-state-after-k-multiplication-operations-i | Easy Code || Beginner-friendly || Newbie | easy-code-beginner-friendly-newbie-by-ha-3taw | IntuitionThe problem revolves around repeatedly identifying the smallest number in an array and modifying it in a specified way (x → x * multiplier).Approach
It | HarshitZenith3 | NORMAL | 2024-12-16T04:39:36.366796+00:00 | 2024-12-16T04:39:36.366796+00:00 | 30 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem revolves around repeatedly identifying the smallest number in an array and modifying it in a specified way (x \u2192 x * multiplier).\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Iterate k Times... | 4 | 0 | ['C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.