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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
search-suggestions-system | [Python 3] Binary Search | python-3-binary-search-by-sb26-xz7y | \'\'\'\n\tdef suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n \n \n products.sort()\n \n | sb26 | NORMAL | 2020-07-11T23:02:02.510718+00:00 | 2020-07-11T23:02:02.510762+00:00 | 623 | false | \'\'\'\n\tdef suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n \n \n products.sort()\n \n s=\'\'\n ans=[]\n \n \n def bin_search(array,word):\n lo=0\n hi=len(array)\n \n while lo... | 5 | 0 | ['Binary Search', 'Python', 'Python3'] | 3 |
search-suggestions-system | Java 96% fast with explanation | java-96-fast-with-explanation-by-anjali1-luqt | If you found the solution interesting, kindly upvote. :)\n\n\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String search | anjali100btcse17 | NORMAL | 2020-07-03T12:07:30.403190+00:00 | 2020-07-03T12:07:30.403226+00:00 | 350 | false | If you found the solution interesting, kindly upvote. :)\n\n```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n \tList<List<String>> res= new ArrayList<List<String>>();\n \tint low=0, high= products.length-1;\n \tint min=0;\n \tArrays.sort(pro... | 5 | 0 | [] | 1 |
search-suggestions-system | [Python] 5 lines, just short | python-5-lines-just-short-by-rkys-18l2 | \nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n ans, products = [], sorted(products)\n | rkys | NORMAL | 2020-02-14T05:18:24.283284+00:00 | 2020-02-14T05:18:24.283321+00:00 | 414 | false | ```\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n ans, products = [], sorted(products)\n for i in range(len(searchWord)):\n products = [p for p in products if i < len(p) and searchWord[i] == p[i]]\n ans.append(products[:... | 5 | 0 | ['Python'] | 1 |
search-suggestions-system | Simple and Easy JAVA Solution | simple-and-easy-java-solution-by-imranan-0r6l | \nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n Arrays.sort(products);\n \n L | imranansari | NORMAL | 2020-02-10T09:38:19.561086+00:00 | 2020-02-10T09:38:55.441841+00:00 | 476 | false | ```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n Arrays.sort(products);\n \n List<List<String>> res = new ArrayList<>();\n for (int i = 0; i < searchWord.length(); i++) {\n String word = searchWord.substring(0,i+1);\n... | 5 | 0 | ['Java'] | 0 |
search-suggestions-system | python, Time: O(mnlog(n)) [99.9%], Space: O(1) [100.0%], squeeze, clean, full comment | python-time-omnlogn-999-space-o1-1000-sq-d04f | Complexity Analysis:\nTime: O(mnlog(n)+m+n), can be simplify as O(mnlog(n))\nSpace: O(1) [100.0%]\nWhere:\n m: max length among len(searchWord) and products\n n | chumicat | NORMAL | 2019-11-28T05:42:21.842462+00:00 | 2019-12-02T10:22:25.072821+00:00 | 1,230 | false | ## Complexity Analysis:\nTime: O(mnlog(n)+m+n), can be simplify as O(mnlog(n))\nSpace: O(1) [100.0%]\nWhere:\n* m: max length among len(searchWord) and products\n* n: len(products)\n* ret space is not included\n\nSince it useing sorting, Time complexity = sort times*each check complexity = nlog(n) * m\n\n```python\n# D... | 5 | 0 | ['Python', 'Python3'] | 2 |
search-suggestions-system | JavaScript simple solution | javascript-simple-solution-by-yyoon-948i | ```\nvar suggestedProducts = function(products, searchWord) {\n products.sort();\n let i = 1;\n let answers = [];\n while (i <= searchWord.length) { | yyoon | NORMAL | 2019-11-24T04:49:04.959772+00:00 | 2019-11-24T04:49:04.959831+00:00 | 343 | false | ```\nvar suggestedProducts = function(products, searchWord) {\n products.sort();\n let i = 1;\n let answers = [];\n while (i <= searchWord.length) {\n let sw = searchWord.substring(0, i);\n let tmp = products.filter(p => p.substring(0,i) === sw);\n if (tmp.length > 3) tmp.length = 3;\n a... | 5 | 0 | [] | 1 |
search-suggestions-system | [C++] Trie Method | c-trie-method-by-orangezeit-8vwq | UPDATE\nSince we only have lowercase letters, the following codes could be slightly improved by using\n\n\nstruct TrieNode {\n int nums;\n vector<TrieNode | orangezeit | NORMAL | 2019-11-24T04:02:56.544029+00:00 | 2019-11-24T05:53:58.003474+00:00 | 562 | false | **UPDATE**\nSince we only have lowercase letters, the following codes could be slightly improved by using\n\n```\nstruct TrieNode {\n int nums;\n vector<TrieNode*> m;\n TrieNode(): nums(0) { m.resize(26); }\n};\n```\nsince vector has a simpler underlying structure in STL. However, map is more scalable if the n... | 5 | 2 | ['Trie'] | 4 |
search-suggestions-system | Very Easy using Linq on C# | very-easy-using-linq-on-c-by-daviti-yz1c | \npublic IList<IList<string>> SuggestedProducts(string[] products, string searchWord)\n {\n var filteredProducts = products.OrderBy(prod=>prod | daviti | NORMAL | 2019-11-24T04:01:18.650129+00:00 | 2019-11-24T04:01:18.650167+00:00 | 674 | false | ```\npublic IList<IList<string>> SuggestedProducts(string[] products, string searchWord)\n {\n var filteredProducts = products.OrderBy(prod=>prod).ToList();\n var resList = new List<IList<string>>();\n for (int len = 1; len <= searchWord.Length; len++)\n {\n ... | 5 | 1 | [] | 1 |
search-suggestions-system | Java Bruteforce 99% faster 😁 | java-bruteforce-99-faster-by-deleted_use-cm4s | Intuition\nThe problem is about suggesting products based on a search word. To find the best suggestions, we need to sort the list of products alphabetically, t | deleted_user | NORMAL | 2024-04-20T21:59:09.420830+00:00 | 2024-04-20T21:59:09.420871+00:00 | 825 | false | # Intuition\nThe problem is about suggesting products based on a search word. To find the best suggestions, we need to sort the list of products alphabetically, then for each prefix derived from the search word, identify the products that start with that prefix.\n# Approach\nSorting Products: Begin by sorting the array... | 4 | 0 | ['Java'] | 0 |
search-suggestions-system | C++ || Intuitive Trie Solution || Beats 75% | c-intuitive-trie-solution-beats-75-by-sh-pgle | Intuition\nSince the problem involves strings and prefixes, my immediate thought was to implement a solution using Trie. We can store each word in the trie and | shobhitkumar43 | NORMAL | 2023-09-07T22:57:05.721953+00:00 | 2023-09-07T22:57:31.403726+00:00 | 662 | false | # Intuition\nSince the problem involves strings and prefixes, my immediate thought was to implement a solution using Trie. We can store each word in the trie and for each prefix also store the words for which it acts as a prefix.\n\n# Approach\nWe implement a basic Trie data structure with additional vector of strings ... | 4 | 0 | ['String', 'Trie', 'C++'] | 2 |
search-suggestions-system | Trie Implementation | C++ | Easy Solution | trie-implementation-c-easy-solution-by-j-yzz4 | Intuition\nTrie(prefix-tree) data structure is standard type of data structure for solving dictionary related problems.\n Describe your first thoughts on how to | Jeetaksh | NORMAL | 2023-06-12T19:53:48.275879+00:00 | 2023-06-12T19:53:48.275900+00:00 | 1,366 | false | # Intuition\nTrie(prefix-tree) data structure is standard type of data structure for solving dictionary related problems.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- Create a Trie data structure to store the products.\n- Insert each product into the Trie.\n- Initialize an empty... | 4 | 0 | ['C++'] | 0 |
search-suggestions-system | ✅EASY TRIE SOLUTION C++ | easy-trie-solution-c-by-amangupta12207-wxfs | Intuition\nInsert All products in trie. And then search for suggestions for each prefix of SearchTerm.\n\n# Code\n\nclass Solution {\npublic:\n struct Node { | Amangupta12207 | NORMAL | 2022-12-18T11:04:13.408981+00:00 | 2022-12-18T11:04:57.246830+00:00 | 576 | false | # Intuition\nInsert All products in trie. And then search for suggestions for each prefix of SearchTerm.\n\n# Code\n```\nclass Solution {\npublic:\n struct Node {\n Node * links[26];\n bool flag = false;\n bool isContains(char ch){ // Node has ch or not\n return links[ch-\'a\'] ... | 4 | 0 | ['Trie', 'C++'] | 0 |
search-suggestions-system | Some Leet Code Problem's Java Solutions Based On Tries Data Structure | some-leet-code-problems-java-solutions-b-i50u | 1268 : Search Suggestions System\n1233 : Remove Sub-Folders from the Filesystem\n648\t: Replace Words\n820\t: Short Encoding of Words\n208\t: Implement Trie (Pr | nitwmanish | NORMAL | 2022-10-03T07:11:32.573338+00:00 | 2023-01-27T00:30:51.232332+00:00 | 256 | false | [1268 : Search Suggestions System](https://leetcode.com/problems/search-suggestions-system/discuss/2638534/java-solution-using-trie-runtime-37-ms-beats-7219)\n[1233 : Remove Sub-Folders from the Filesystem](https://leetcode.com/problems/remove-sub-folders-from-the-filesystem/discuss/2638522/java-solution-using-trie-run... | 4 | 0 | ['Tree', 'Trie', 'Java'] | 0 |
search-suggestions-system | Using Trie and why the performance is not good as expected | using-trie-and-why-the-performance-is-no-29lo | I think many of you want to solve this problem with Trie(Prefix Tree) like me. And after we code it out, submit it, we found we need to cost around 10 times tha | cgrieftesla | NORMAL | 2022-06-29T11:13:34.131318+00:00 | 2022-06-29T11:13:34.131351+00:00 | 448 | false | I think many of you want to solve this problem with **Trie(Prefix Tree)** like me. And after we code it out, submit it, we found we need to cost around 10 times than other people\'s brute force way. This time you might be confused, frustrated and want to know why. Here is my analysis.\n\nI import "**time**" to do the a... | 4 | 0 | ['Depth-First Search', 'Trie', 'Python'] | 0 |
search-suggestions-system | Search Suggestions System | Without using Trie | Java Solution | search-suggestions-system-without-using-ni97q | \nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> ans = new ArrayList<>(); | shaguftashahroz09 | NORMAL | 2022-06-19T16:30:20.433874+00:00 | 2022-06-19T16:30:20.434063+00:00 | 105 | false | ```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> ans = new ArrayList<>();\n Arrays.sort(products);\n int l=0,r=products.length-1;\n String start="";\n for(int i=0;i<searchWord.length();i++)\n {\n... | 4 | 0 | ['Java'] | 0 |
search-suggestions-system | ✅C++ | ✅2 Approaches | ✅Use Binary Search | ✅Efficient Solution | 🗓️ DLC June, Day 19 | c-2-approaches-use-binary-search-efficie-ic10 | Brute-Force:\n\nTC : O(NlogN + NxS^2)\nSc : O(1) - vector> is return type so it is not counted\nHere,\n N : size of products\n S : size of searchedword\n | Yash2arma | NORMAL | 2022-06-19T16:09:17.254007+00:00 | 2022-06-19T16:09:17.254051+00:00 | 489 | false | **Brute-Force:**\n\n**TC : O(NlogN + NxS^2)\nSc : O(1)** - vector<vector<string>> is return type so it is not counted\nHere,\n N : size of products\n S : size of searchedword\n NlogN : For sorting\n NXS^2 : We find S size words in N products and making S size substrings\n\n**Code:**\n```\nclass Solution {\n... | 4 | 0 | ['String', 'C', 'Sorting', 'Binary Tree', 'C++'] | 1 |
search-suggestions-system | Java Solution Using String | java-solution-using-string-by-samarth-kh-cwtz | Approach 1\n\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> ans = new Ar | Samarth-Khatri | NORMAL | 2022-06-19T12:41:16.282901+00:00 | 2022-06-19T13:33:21.360141+00:00 | 547 | false | # Approach 1\n```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> ans = new ArrayList();\n Arrays.sort(products);\n String subs="";\n for(int i=0;i<searchWord.length();++i){\n List<String> ians = new A... | 4 | 0 | ['String', 'Java'] | 1 |
search-suggestions-system | Efficient C++ Solution using binary-search | efficient-c-solution-using-binary-search-nv35 | Please upvote this post if you like my solution/approach.\n\ncpp\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string> &produc | travanj05 | NORMAL | 2022-06-19T10:58:40.066189+00:00 | 2022-07-03T18:20:00.959101+00:00 | 314 | false | Please **upvote** this post if you like my solution/approach.\n\n```cpp\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string> &products, string &searchWord) {\n vector<vector<string>> res;\n sort(products.begin(), products.end());\n int l = 0, r = products.size() -... | 4 | 0 | ['C', 'Binary Tree', 'C++'] | 1 |
search-suggestions-system | Simple Easy Approach | simple-easy-approach-by-vaibhav7860-6uc4 | \nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n product = []\n for i in range(len(s | vaibhav7860 | NORMAL | 2022-06-19T06:19:27.858930+00:00 | 2022-06-19T06:19:27.858970+00:00 | 949 | false | ```\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n product = []\n for i in range(len(searchWord)):\n p = []\n for prod in products:\n if prod.startswith(searchWord[:i+1]):\n p.append(prod... | 4 | 0 | ['Python', 'Python3'] | 4 |
search-suggestions-system | Simple and easily understandable solution | simple-and-easily-understandable-solutio-hdj7 | First sort the words array that was which will actually sort the words in lexographical order.\nNow find out the words that have 1st letter as common with that | Sathish_McCall | NORMAL | 2022-06-19T06:19:13.688816+00:00 | 2022-06-19T06:25:35.818047+00:00 | 142 | false | First sort the words array that was which will actually sort the words in lexographical order.\nNow find out the words that have 1st letter as common with that of search word and append them to dp array.\nNext we will search for the second letter from the dp array of 1st letter ,\nAnd we will continue till the end .\nA... | 4 | 0 | [] | 0 |
search-suggestions-system | Python Trie Solution | python-trie-solution-by-shams7-5nwl | \nclass TrieNode:\n def __init__(self,char):\n self.char = char\n self.isWord = False\n self.children = {}\n\nclass Trie:\n def __ini | shams7 | NORMAL | 2022-05-15T15:47:30.673818+00:00 | 2022-05-15T15:47:30.673903+00:00 | 205 | false | ```\nclass TrieNode:\n def __init__(self,char):\n self.char = char\n self.isWord = False\n self.children = {}\n\nclass Trie:\n def __init__(self):\n self.root = TrieNode("")\n \n def insert(self,word):\n node = self.root\n\n for char in word:\n if char in... | 4 | 0 | ['Depth-First Search', 'Trie', 'Python'] | 1 |
search-suggestions-system | [Python] Trie solution explained | python-trie-solution-explained-by-buccat-rbuy | \nclass TrieNode:\n def __init__(self):\n self.children = {}\n self.end = False\n self.suggestions = list()\n\nclass Solution:\n def | buccatini | NORMAL | 2022-04-14T02:15:57.125411+00:00 | 2022-04-14T02:15:57.125437+00:00 | 386 | false | ```\nclass TrieNode:\n def __init__(self):\n self.children = {}\n self.end = False\n self.suggestions = list()\n\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n root = TrieNode()\n \n # sort the input lexicographi... | 4 | 0 | ['Trie', 'Python', 'Python3'] | 2 |
search-suggestions-system | [Python] Simple approach using Brute Force (84 ms, faster than 93.2%) | python-simple-approach-using-brute-force-x0mh | class Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n \n res = []\n\t\t# Initializing empty | amanc1997 | NORMAL | 2022-03-07T09:19:14.618420+00:00 | 2022-03-07T09:19:14.618461+00:00 | 268 | false | class Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n \n res = []\n\t\t# Initializing empty string temp\n temp = \'\'\n \n\t\t# Sorting the list \n products.sort()\n \n\t\t# Looping through searchWord\n for word in s... | 4 | 0 | ['Python', 'Python3'] | 0 |
search-suggestions-system | Java | Trie | OOP | java-trie-oop-by-arrnavvv-f7sa | \n\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n Trie trie = new Trie();\n Arrays.s | arrnavvv | NORMAL | 2022-02-23T15:02:05.020943+00:00 | 2022-02-23T15:02:05.020971+00:00 | 295 | false | \n```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n Trie trie = new Trie();\n Arrays.sort(products);\n for(String p : products){\n trie.insert(p);\n }\n \n List<List<String>> res = trie.getResult(searchWo... | 4 | 0 | ['Trie', 'Java'] | 1 |
search-suggestions-system | [C++] Binary search & trie | c-binary-search-trie-by-codedayday-f936 | Approach 1: Binary Search [1]\nTime Complexity: O(NlogN) + O(MlogN), where N=|products|, M= |searchWord|\nSpace: O(1)\n\nclass Solution {\npublic:\n vector<v | codedayday | NORMAL | 2021-05-31T17:15:57.039571+00:00 | 2021-05-31T17:38:15.653533+00:00 | 256 | false | Approach 1: Binary Search [1]\nTime Complexity: O(NlogN) + O(MlogN), where N=|products|, M= |searchWord|\nSpace: O(1)\n```\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> ans;\n sort(products.begin(), products... | 4 | 0 | ['Trie', 'C', 'Binary Tree'] | 2 |
search-suggestions-system | C++ 2 approaches (Binary Search , Trie) Easy to undersrand code | c-2-approaches-binary-search-trie-easy-t-0txz | Github Link : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Design/Search_Suggestions_System.cpp\n\n//Approach - 1 (First solution that comes in ou | mazhar_mik | NORMAL | 2021-05-31T15:58:13.730244+00:00 | 2021-05-31T15:58:13.730296+00:00 | 71 | false | Github Link : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Design/Search_Suggestions_System.cpp\n```\n//Approach - 1 (First solution that comes in our mind : Using TRIE Data Structure)\nclass Solution {\npublic:\n struct trieNode {\n char ch;\n bool end;\n trieNode* children[26] = ... | 4 | 0 | [] | 0 |
search-suggestions-system | Search Suggestion System | Python | Brute Force | search-suggestion-system-python-brute-fo-fidc | Sort the products array to get lexicographically smallest words and then iterate over products till length of target and check for at most three matching words | sethhritik | NORMAL | 2021-05-31T12:12:57.364679+00:00 | 2021-05-31T12:12:57.364721+00:00 | 240 | false | Sort the products array to get *lexicographically smallest* words and then iterate over products till length of target and check for **at most** three matching words in products with **prefix[0:i+1]**.\n\n```\ndef suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n ans=[]\n ... | 4 | 0 | ['Sliding Window', 'Python', 'Python3'] | 0 |
search-suggestions-system | Python 7-line solution | python-7-line-solution-by-julescui-0oi9 | \nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n result = []\n products.sort()\n | JulesCui | NORMAL | 2021-01-13T22:19:36.165499+00:00 | 2021-01-13T22:19:36.165538+00:00 | 362 | false | ```\nclass Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n result = []\n products.sort()\n for x in range(len(searchWord)):\n word = searchWord[:x+1]\n products = [item for item in products if item.startswith(word)]\n ... | 4 | 0 | ['Python', 'Python3'] | 1 |
search-suggestions-system | Java concise Trie | java-concise-trie-by-hjscoder-m8db | Code: \n\n\nclass Solution {\n class Node {\n char val;\n HashMap<Character, Node> children;\n List<String> suggestion;\n publi | hjscoder | NORMAL | 2020-09-04T19:51:01.202133+00:00 | 2020-09-04T19:51:01.202173+00:00 | 225 | false | <h4> Code: </h4>\n\n```\nclass Solution {\n class Node {\n char val;\n HashMap<Character, Node> children;\n List<String> suggestion;\n public Node(char val) {\n this.val = val;\n this.children = new HashMap<Character, Node>();\n this.suggestion = new Array... | 4 | 0 | [] | 0 |
search-suggestions-system | JAVA beats 97.45% time(7ms) 100% memory... No Trie, No Binary Search | java-beats-9745-time7ms-100-memory-no-tr-m9e0 | \nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> ans = new ArrayList<>(); | vision2yrs | NORMAL | 2020-05-14T08:18:00.300667+00:00 | 2020-05-14T08:19:59.228533+00:00 | 556 | false | ```\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n List<List<String>> ans = new ArrayList<>();\n for (int i = 0; i < searchWord.length(); ++i) {\n ans.add(new ArrayList<>());\n }\n List<String> temp = null;\n Arr... | 4 | 0 | ['Java'] | 0 |
search-suggestions-system | Swift Trie | swift-trie-by-charlychuanli-wdjq | ```\nfunc suggestedProducts( products: [String], _ searchWord: String) -> [[String]] {\n var root = Trie()\n for product in products {\n | charlychuanli | NORMAL | 2020-05-09T23:35:27.761147+00:00 | 2020-05-09T23:35:27.761199+00:00 | 290 | false | ```\nfunc suggestedProducts(_ products: [String], _ searchWord: String) -> [[String]] {\n var root = Trie()\n for product in products {\n var cur = root\n cur.build(cur, product)\n }\n var res = [[String]]()\n \n for char in searchWord {\n \n ... | 4 | 0 | [] | 3 |
search-suggestions-system | SIMPLE BINARY SEARCH C++ SOLUTION | simple-binary-search-c-solution-by-jeffr-5a39 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Jeffrin2005 | NORMAL | 2024-08-10T04:37:09.912003+00:00 | 2024-08-10T04:37:09.912026+00:00 | 799 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 0 | ['C++'] | 0 |
search-suggestions-system | Search Suggestions System C++ Solution | search-suggestions-system-c-solution-by-cjdny | Code\n\nstruct Node{\n Node* links[26];\n bool flag = false;\n vector<string>words;\n bool containsKey(char ch){\n return links[ch-\'a\']!=NU | rissabh361 | NORMAL | 2023-09-12T18:00:35.859400+00:00 | 2023-09-12T18:00:35.859424+00:00 | 1,135 | false | # Code\n```\nstruct Node{\n Node* links[26];\n bool flag = false;\n vector<string>words;\n bool containsKey(char ch){\n return links[ch-\'a\']!=NULL;\n }\n void put(char ch,Node* node){\n links[ch-\'a\'] = node;\n }\n Node* get(char ch){\n return links[ch-\'a\'];\n }\n ... | 3 | 0 | ['Array', 'String', 'Binary Search', 'Trie', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 0 |
search-suggestions-system | [Java] 2 solutions: Sorting (100%) / using Trie and BackTracking (65%) | java-2-solutions-sorting-100-using-trie-et5x3 | 65% runtime, but better if we had to reuse the search function (in a design scenario).\n\njava\nclass Solution {\n public List<List<String>> suggestedProduct | YTchouar | NORMAL | 2023-05-31T18:59:17.321306+00:00 | 2023-05-31T21:12:33.842681+00:00 | 540 | false | 65% runtime, but better if we had to reuse the search function (in a design scenario).\n\n```java\nclass Solution {\n public List<List<String>> suggestedProducts(String[] products, String searchWord) {\n final TrieNode root = this.buildTree(products);\n final List<List<String>> result = new ArrayList<>... | 3 | 0 | ['Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | c++ 2 pointers with detail proof and explanation | c-2-pointers-with-detail-proof-and-expla-h3sy | In this post I \'m not trying to give the most efficient algorithm or the simplest code. I just try to explain the essence of the problem.\n\nA palindrome is an | hl1008 | NORMAL | 2022-03-13T20:08:46.843303+00:00 | 2022-05-21T12:19:30.901521+00:00 | 16,438 | false | In this post I \'m not trying to give the most efficient algorithm or the simplest code. I just try to explain the essence of the problem.\n\nA palindrome is an axial symmetry string. Every position holds the same letter with its position symmetry. \n\n<img src="https://assets.leetcode.com/users/images/05b7eb94-bdf5-40... | 306 | 0 | ['C', 'C++'] | 21 |
minimum-number-of-moves-to-make-palindrome | [C++/Python] Short Greedy Solution | cpython-short-greedy-solution-by-lee215-1yx1 | Explanation\nConsidering the first and the last char in final palindrome.\nIf they are neither the first nor the last char in the initial string,\nyou must wast | lee215 | NORMAL | 2022-03-05T16:14:38.594921+00:00 | 2022-03-05T16:53:58.514556+00:00 | 18,025 | false | # **Explanation**\nConsidering the first and the last char in final palindrome.\nIf they are neither the first nor the last char in the initial string,\nyou must waste some steps:\nAssume start with "...a....a.."\n".a.......a." can be ealier completed thand "a.........a".\n\nThen compare the situation "a....b..a...b"\n... | 186 | 5 | [] | 26 |
minimum-number-of-moves-to-make-palindrome | [Java, C++] 2 pointers. Step-by-step dry-run for easy explanation | java-c-2-pointers-step-by-step-dry-run-f-bahk | Below is the dry-run and detailed steps using example string "aletelt". Do "Upvote" if it helps :) \n\t\n#### \tComplexity\n\tTime: O(n^2), Space: O(n)\n\t\n# | karankhara | NORMAL | 2022-03-05T22:49:16.888405+00:00 | 2022-03-14T22:31:02.068826+00:00 | 9,483 | false | Below is the dry-run and detailed steps using example string "aletelt". Do "**Upvote**" if it helps :) \n\t\n#### \tComplexity\n\tTime: O(n^2), Space: O(n)\n\t\n#### \tApproach:\n\tIntially, steps = 0.\n\t* \tWe will use 2 index pointers initially - "l" as Left and "r" as right. \n\t* \t\'l\' will move to right and ... | 131 | 3 | ['Greedy', 'C', 'Java'] | 12 |
minimum-number-of-moves-to-make-palindrome | [Python] 2 solutions: O(n^2) and O(n log n), explained | python-2-solutions-on2-and-on-log-n-expl-1e9d | Solution 1\nThe idea is to greedy construct palindrome, symbol by symbol, using two pointers technique. Imagine that we have abc...cdeba. Then for the first two | dbabichev | NORMAL | 2022-03-05T16:01:33.742718+00:00 | 2022-03-05T16:20:50.822946+00:00 | 7,547 | false | #### Solution 1\nThe idea is to greedy construct palindrome, symbol by symbol, using two pointers technique. Imagine that we have `abc...cdeba`. Then for the first two symbols they are already on place. For symbol `c`, we start form the `-3` symbol and look for symbol `c`. When we found it, we do swaps. So, we have `ab... | 66 | 7 | ['Two Pointers', 'Greedy'] | 13 |
minimum-number-of-moves-to-make-palindrome | List vs. BIT | list-vs-bit-by-votrubac-ry9g | This question sounds intimidating. Even with 2,000 characters, full search is not practical. Thus, we need to figure out some greedy approach.\n \nIntuition | votrubac | NORMAL | 2022-03-05T16:00:30.231609+00:00 | 2022-03-06T22:21:27.406022+00:00 | 4,912 | false | This question sounds intimidating. Even with 2,000 characters, full search is not practical. Thus, we need to figure out some greedy approach.\n \n**Intuition 1:** It is always cheaper to keep either the left or right character in place, as opposed to moving some other character to the left and right.\n \n **Intuiti... | 51 | 3 | ['C'] | 12 |
minimum-number-of-moves-to-make-palindrome | Java solution using Greedy | java-solution-using-greedy-by-hss15-g4oy | If a character is at boundry, there is not point in moving it towards center.\nAt any given moment, there can be 2 option for making the boundry palindrome.\nCh | hss15 | NORMAL | 2022-03-05T16:01:07.405812+00:00 | 2022-03-05T16:06:34.691787+00:00 | 4,503 | false | If a character is at boundry, there is not point in moving it towards center.\nAt any given moment, there can be 2 option for making the boundry palindrome.\nChoose the one with minimum value greedily and keep updating the string.\n\n```\nclass Solution {\n public int minMovesToMakePalindrome(String s) {\n in... | 47 | 0 | ['Greedy', 'Java'] | 6 |
minimum-number-of-moves-to-make-palindrome | [Python3] 2 pointers solution explained | python3-2-pointers-solution-explained-by-94i1 | \n\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n """\n 2 pointers, left and right, such that right = n - left - 1\n | prasanna648 | NORMAL | 2022-03-05T16:02:00.281262+00:00 | 2022-03-05T16:03:33.074818+00:00 | 3,019 | false | ```\n\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n """\n 2 pointers, left and right, such that right = n - left - 1\n i.e., they are equidistant from both ends\n \n in a palindromic arrangement of s, s[left] == s[right]\n\n if s[left] and s[right] ... | 34 | 2 | [] | 5 |
minimum-number-of-moves-to-make-palindrome | Two pointer | C++ | two-pointer-c-by-zuks_100-wlnw | \nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int n = s.length();\n \n int left = 0, right = s.size() - 1, ans = 0 | zuks_100 | NORMAL | 2022-03-05T16:18:28.486994+00:00 | 2022-03-05T16:19:58.413110+00:00 | 3,595 | false | ```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int n = s.length();\n \n int left = 0, right = s.size() - 1, ans = 0;\n while (left < right) {\n int l = left, r = right;\n while (s[l] != s[r]) r--; \n if (l == r) {\n // here we hit the ... | 26 | 1 | ['C', 'C++'] | 5 |
minimum-number-of-moves-to-make-palindrome | C++||Two Pointer Greedy Approach | ctwo-pointer-greedy-approach-by-be_quick-acb9 | \nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int n = s.length();\n int i =0,j=n-1;\n int ans = 0;\n whi | be_quick | NORMAL | 2022-03-05T16:41:15.524442+00:00 | 2022-03-05T17:06:56.791913+00:00 | 1,813 | false | ```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int n = s.length();\n int i =0,j=n-1;\n int ans = 0;\n while(i<j){\n if(s[i]==s[j]){ // Both Characters are same move 2 pointers\n i++;\n j--;\n }else{\n\t\t\t... | 16 | 0 | ['Two Pointers', 'Greedy', 'C++'] | 3 |
minimum-number-of-moves-to-make-palindrome | [Python] with proof for why move a from the form of a....a.... to a.......a works | python-with-proof-for-why-move-a-from-th-zrh2 | Proof\nProvide with a not very solid but acceptable proof:\n\n(1) let\'s convert the string to an array to \nexample: "abcab" -> ["a", "b", "c", "a", "b"]\n\n(2 | cathatino | NORMAL | 2022-03-05T19:45:40.838763+00:00 | 2022-03-06T06:07:01.764600+00:00 | 1,910 | false | # Proof\nProvide with a not very solid but acceptable proof:\n\n(1) let\'s convert the string to an array to \nexample: `"abcab"` -> `["a", "b", "c", "a", "b"]`\n\n(2) let\'s only consider to move `first element` to be Palindrome. In our example\n\nit will be to move from the form of\n`["a", ..., "a", ...]`\nlet\'s ass... | 12 | 0 | ['Greedy', 'Recursion', 'Python'] | 1 |
minimum-number-of-moves-to-make-palindrome | Clean Java Code With Explanation | clean-java-code-with-explanation-by-subh-xb84 | Check if the character in start and end index are same if yes then decrease the end by 1 and increase the start by 1\n Otherwise search for the character simila | subham_99 | NORMAL | 2022-08-23T05:22:58.981409+00:00 | 2022-08-23T05:22:58.981452+00:00 | 1,652 | false | * **Check if the character in start and end index are same if yes then decrease the end by 1 and increase the start by 1**\n* **Otherwise search for the character similar to the starting index by decrementing the end** \n* **If it is seen that on decrementing the end it points to same index as start then swap the cha... | 10 | 0 | ['Two Pointers', 'Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | C++ Greedy solution with explanation | c-greedy-solution-with-explanation-by-na-yly1 | Approach:\nWhen do you say that the string is Palindrome?\nWhen it reads same forward and backward right.\nThis is what we will try to do in this approach.\n\nW | naman-1234 | NORMAL | 2022-03-08T18:57:10.365152+00:00 | 2022-03-08T18:58:10.278011+00:00 | 1,281 | false | ## Approach:\nWhen do you say that the string is Palindrome?\nWhen it reads same forward and backward right.\nThis is what we will try to do in this approach.\n\nWe will go with same approach.\n- We will go with first half of the elements and see if their corresponding character from last is equal, If it is equal then ... | 10 | 0 | ['Greedy', 'C', 'C++'] | 1 |
minimum-number-of-moves-to-make-palindrome | C++ solutions | c-solutions-by-infox_92-j7fg | \nclass Solution {\nprivate:\n void swap(string& s, int i, int j){\n char t = s[i];\n s[i] = s[j];\n s[j] = t;\n }\npublic:\n int | Infox_92 | NORMAL | 2022-11-21T11:55:29.530938+00:00 | 2022-11-21T11:55:29.530973+00:00 | 1,137 | false | ```\nclass Solution {\nprivate:\n void swap(string& s, int i, int j){\n char t = s[i];\n s[i] = s[j];\n s[j] = t;\n }\npublic:\n int minMovesToMakePalindrome(string s) {\n int ans = 0, l = 0, r = s.size() - 1;\n \n while(l < r){\n if(s[l] == s[r]){\n ... | 8 | 0 | ['C++'] | 1 |
minimum-number-of-moves-to-make-palindrome | JAVA | EASY | EXPLANATION | TWO POINTER | java-easy-explanation-two-pointer-by-bha-sybs | class Solution {\n public int minMovesToMakePalindrome(String s) {\n \n char []arr=s.toCharArray();\n int start=0;\n int n=s.leng | bharat0512 | NORMAL | 2022-03-24T18:54:02.638019+00:00 | 2022-06-30T05:20:41.868891+00:00 | 1,942 | false | class Solution {\n public int minMovesToMakePalindrome(String s) {\n \n char []arr=s.toCharArray();\n int start=0;\n int n=s.length();\n int end=s.length()-1;\n int res=0;\n while(start<end)\n {\n int k=end;\n // if we found pal char \n ... | 7 | 0 | ['Java'] | 3 |
minimum-number-of-moves-to-make-palindrome | [Python] simple solution with graphic explanation | python-simple-solution-with-graphic-expl-nx4x | start from the first letter. we can tell that its corresponding position is the last index n - 1. Search for the right most same letter and swap it to the targe | huayu_ivy | NORMAL | 2022-03-05T16:07:01.504229+00:00 | 2022-03-05T16:17:33.794117+00:00 | 1,287 | false | * start from the first letter. we can tell that its corresponding position is the last index `n - 1`. Search for the right most same letter and swap it to the target position\n\n\n* if we cannot find a same let... | 7 | 0 | ['Python'] | 1 |
minimum-number-of-moves-to-make-palindrome | C++ || Two Pointer || Easy Understanding | c-two-pointer-easy-understanding-by-gnan-zcar | class Solution {\npublic:\n\n int minMovesToMakePalindrome(string s) {\n int n=s.size();\n int p=0;\n int q=n-1;\n int ans=0;\n | GnanaPrakash9 | NORMAL | 2022-07-11T06:08:08.494556+00:00 | 2022-10-02T12:15:00.907328+00:00 | 2,289 | false | class Solution {\npublic:\n\n int minMovesToMakePalindrome(string s) {\n int n=s.size();\n int p=0;\n int q=n-1;\n int ans=0;\n int y=-1;\n while(p<=q)\n {\n if(s[p]!=s[q])\n {\n int temp=q-1;\n while(s[temp]!=s[p])\... | 6 | 0 | ['Two Pointers', 'Greedy', 'C++'] | 3 |
minimum-number-of-moves-to-make-palindrome | Without considering any odd element case using two pointer method | without-considering-any-odd-element-case-ceyz | Hello guys,\nthis is a simple solution for Minimum Number of Moves to Make Palindrome problem\n\nLet l=0, r=n-1\n\nif(s[l]==s[r]) l++,r--;\n\nelse\n{\nsearch s | aakaxh | NORMAL | 2022-06-11T11:41:28.754921+00:00 | 2022-06-11T11:42:01.808868+00:00 | 289 | false | **Hello guys,**\nthis is a simple solution for `Minimum Number of Moves to Make Palindrome` problem\n\nLet `l=0, r=n-1`\n\n`if(s[l]==s[r]) l++,r--;`\n\n`else`\n`{`\nsearch s[l] from right side of the string \nand seach s[r] from left side of the string\n\nlet we get `s[l]` at `idx2` from right then there will be` r-id... | 5 | 0 | ['Two Pointers'] | 1 |
minimum-number-of-moves-to-make-palindrome | [C++] Runtime: 8 ms, faster than 99.93% | Memory: 6.6 MB, less than 98.24% | c-runtime-8-ms-faster-than-9993-memory-6-xfm8 | \nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int ans = 0;\n \n while(s.length() > 0){\n int n = s | anubhabishere | NORMAL | 2022-03-08T06:00:57.477170+00:00 | 2022-03-08T06:00:57.477214+00:00 | 456 | false | ```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int ans = 0;\n \n while(s.length() > 0){\n int n = s.length();\n char c = s[n-1];\n int ind = s.find(c);\n //cout<<s<<" "<<ind<<" "<<c<<endl;\n if(ind == n-1){\n ... | 5 | 0 | ['Array', 'String', 'C'] | 1 |
minimum-number-of-moves-to-make-palindrome | C# | Memory beats 100.00%, Runtime beats 77.78% [EXPLAINED] | c-memory-beats-10000-runtime-beats-7778-7droc | Intuition\nThe problem requires us to rearrange characters to form a palindrome, which means that characters at symmetric positions should match. To minimize th | r9n | NORMAL | 2024-09-19T19:37:34.727183+00:00 | 2024-09-19T19:37:34.727219+00:00 | 60 | false | # Intuition\nThe problem requires us to rearrange characters to form a palindrome, which means that characters at symmetric positions should match. To minimize the number of swaps, we can perform a greedy approach by finding the best positions for each character and then swapping it into place.\n\n\n# Approach\nTwo-Poi... | 4 | 0 | ['C#'] | 0 |
minimum-number-of-moves-to-make-palindrome | BRUTE FORCE || C++ | brute-force-c-by-ganeshkumawat8740-pzq4 | Code\n\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int i = 0, j = s.length()-1,k,ans=0;\n while(i<j){\n | ganeshkumawat8740 | NORMAL | 2023-06-10T11:23:03.544464+00:00 | 2023-06-10T11:23:14.491216+00:00 | 1,119 | false | # Code\n```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int i = 0, j = s.length()-1,k,ans=0;\n while(i<j){\n if(s[i]==s[j]){\n i++;j--;\n }else{\n k = j;\n while(k>=i && s[k] != s[i]){\n k-... | 4 | 0 | ['Two Pointers', 'String', 'Greedy', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | c++ superfast 92% solution | c-superfast-92-solution-by-shrest-6gus | \nclass Solution {\npublic:\n int solve(string &s,char target,int last,int index)\n {\n int pos=-1;\n for(int i=last;i>=0;i--)\n {\n | SHREST | NORMAL | 2022-03-12T08:29:51.685561+00:00 | 2022-03-12T09:37:57.875120+00:00 | 560 | false | ```\nclass Solution {\npublic:\n int solve(string &s,char target,int last,int index)\n {\n int pos=-1;\n for(int i=last;i>=0;i--)\n {\n if(s[i]==target)\n {\n pos=i;\n break;\n }\n }\n int c=0;\n\t\t//if my string is... | 4 | 0 | ['Greedy', 'C'] | 0 |
minimum-number-of-moves-to-make-palindrome | Explanation - logical proof why greedy works | explanation-logical-proof-why-greedy-wor-rz8e | This may not be a concrete proof but atleast having some idea is better than nothing. I could not find any good explanation out there, so please comment here if | niranjvin | NORMAL | 2022-03-05T16:35:18.754782+00:00 | 2022-03-05T16:36:49.213232+00:00 | 552 | false | This may not be a concrete proof but atleast having some idea is better than nothing. I could not find any good explanation out there, so please comment here if you have found a better resource :)\n\n\nYou might have already read the approach - \n1. initialise left and right pointers to 0 and size-1 respectively\n2. fi... | 4 | 1 | ['Greedy', 'Java'] | 1 |
minimum-number-of-moves-to-make-palindrome | c++ easy swap solution | c-easy-swap-solution-by-lovelydays95-154o | C++\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int res = 0;\n for(int i = 0, j = s.length() - 1; i < s.length() / | lovelydays95 | NORMAL | 2022-03-05T16:01:53.518933+00:00 | 2022-03-05T16:02:31.573231+00:00 | 499 | false | ```C++\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int res = 0;\n for(int i = 0, j = s.length() - 1; i < s.length() / 2; i++, j--) {\n if(s[i] == s[j]) continue;\n int f = j - 1;\n for(; f >= i; f--) { //find closest character\n ... | 4 | 0 | [] | 0 |
minimum-number-of-moves-to-make-palindrome | Python Greedy 2 pointer | python-greedy-2-pointer-by-shubhamnishad-plt4 | \tclass Solution:\n\t\tdef minMovesToMakePalindrome(self, s: str) -> int:\n\t\t\ts = list(s) #makes it easy for assignment op\n\n\t\t\tres = 0\n\t\t\tleft, righ | shubhamnishad25 | NORMAL | 2022-09-12T18:18:42.523984+00:00 | 2022-09-12T18:18:42.524023+00:00 | 925 | false | \tclass Solution:\n\t\tdef minMovesToMakePalindrome(self, s: str) -> int:\n\t\t\ts = list(s) #makes it easy for assignment op\n\n\t\t\tres = 0\n\t\t\tleft, right = 0, len(s) - 1\n\n\t\t\twhile left < right:\n\t\t\t\tl, r = left, right\n\n\t\t\t\t#find matching char\n\t\t\t\twhile s[l] != s[r]:\n\t\t\t\t\tr -= 1\n\n\t\t... | 3 | 0 | ['Python', 'Python3'] | 0 |
minimum-number-of-moves-to-make-palindrome | JAVA SOLUTION || STRING BUILDER || GREEDY || TWO POINTER | java-solution-string-builder-greedy-two-jc525 | \nclass Solution {\n public int minMovesToMakePalindrome(String s) \n {\n int n=s.length();\n StringBuilder sb=new StringBuilder(s);\n | 29nidhishah | NORMAL | 2022-08-20T14:54:22.144708+00:00 | 2022-08-20T14:54:22.144748+00:00 | 838 | false | ```\nclass Solution {\n public int minMovesToMakePalindrome(String s) \n {\n int n=s.length();\n StringBuilder sb=new StringBuilder(s);\n int ans=0;\n \n while(sb.length()>1)\n {\n char ch=sb.charAt(0);\n int pos=sb.lastIndexOf(ch+"");\n \... | 3 | 0 | ['String', 'Greedy', 'Java'] | 3 |
minimum-number-of-moves-to-make-palindrome | Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-cy60 | Using Greedy Approach\n\n Time Complexity : O(N * N)\n Space Complexity : O(1)\n\n\nint minMovesToMakePalindrome(string str) {\n \n int n = str.si | __KR_SHANU_IITG | NORMAL | 2022-04-03T14:32:45.353613+00:00 | 2022-04-03T14:32:45.353663+00:00 | 563 | false | * ***Using Greedy Approach***\n\n* ***Time Complexity : O(N * N)***\n* ***Space Complexity : O(1)***\n\n```\nint minMovesToMakePalindrome(string str) {\n \n int n = str.size();\n \n int low = 0;\n \n int high = n - 1;\n \n int count = 0;\n \n while(l... | 3 | 1 | ['Greedy', 'C'] | 1 |
minimum-number-of-moves-to-make-palindrome | Java | Greedy | Two pointers | java-greedy-two-pointers-by-pratham_ghul-69sl | \nclass Solution {\n public int minMovesToMakePalindrome(String str) {\n int n=str.length();\n char[] s=str.toCharArray();\n int lptr=0; | pratham_ghule | NORMAL | 2022-03-07T10:21:57.318784+00:00 | 2022-03-07T10:21:57.318813+00:00 | 710 | false | ```\nclass Solution {\n public int minMovesToMakePalindrome(String str) {\n int n=str.length();\n char[] s=str.toCharArray();\n int lptr=0;\n int rptr=n-1;\n \n int res=0;\n while(lptr<rptr){\n int r=rptr;\n \n if(s[lptr]==s[r]){\n ... | 3 | 0 | ['Greedy', 'Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | Java O(n log n) Solution with Binary Index Trees | java-on-log-n-solution-with-binary-index-krab | \nclass Solution {\n List<Integer> [] charList;\n int [][] charPointers;\n int [] BIT;\n \n public int minMovesToMakePalindrome(String s) {\n | profchi | NORMAL | 2022-03-05T16:53:54.779581+00:00 | 2022-03-05T16:53:54.779606+00:00 | 926 | false | ```\nclass Solution {\n List<Integer> [] charList;\n int [][] charPointers;\n int [] BIT;\n \n public int minMovesToMakePalindrome(String s) {\n \n charList = new List[26];\n charPointers = new int [26][2];\n BIT = new int [s.length()];\n \n for (int i = 0; i... | 3 | 1 | ['Greedy', 'Binary Indexed Tree'] | 2 |
minimum-number-of-moves-to-make-palindrome | Beats 97.75% || C++ || Greedy | beats-9775-c-greedy-by-akash92-iod7 | Intuition\n Describe your first thoughts on how to solve this problem. \nTo make a string a palindrome, matching pairs of characters should be placed symmetrica | akash92 | NORMAL | 2024-10-02T15:49:16.133225+00:00 | 2024-10-02T15:49:35.502239+00:00 | 274 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo make a string a palindrome, matching pairs of characters should be placed symmetrically from the start and end. For each character at the back, we look for its matching character in the remaining part of the string, move it to the corr... | 2 | 0 | ['String', 'Greedy', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | 🧧Easy Understandable C++ Solution || Greedy + Two-Pointers | easy-understandable-c-solution-greedy-tw-pkkd | Intuition + Approach\n- We basically try to convert the second half of the string into the first half.\n- To do this, We greedily pick the closest element to th | teqarine | NORMAL | 2023-07-18T21:15:55.710016+00:00 | 2023-07-18T21:15:55.710042+00:00 | 74 | false | # Intuition + Approach\n- We basically try to convert the second half of the string into the first half.\n- To do this, We greedily pick the closest element to the right pointer and swap it until we reach its correct position, i..e.. (n-i-1).\n- An edge case will be when the length of the string is odd and there\'s a c... | 2 | 0 | ['C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | Intuition Made Easy for you | C++ Explanation | intuition-made-easy-for-you-c-explanatio-kjpn | ```\nint solve(string s)\n {\n int n=s.size(),ans=0,i=0,j=n-1;\n \n while(iWe are fixing the first half and changing 2nd half accordin | kunalrautela | NORMAL | 2022-10-29T11:40:09.409145+00:00 | 2022-10-29T11:40:09.409190+00:00 | 98 | false | ```\nint solve(string s)\n {\n int n=s.size(),ans=0,i=0,j=n-1;\n \n while(i<j)\n {\n if(s[i]!=s[j])\n {\n //Step 1 ->We are fixing the first half and changing 2nd half according to it \n \n int idx=j;\n while(s[id... | 2 | 0 | [] | 1 |
minimum-number-of-moves-to-make-palindrome | C++||Two Pointers||Easy to Understand | ctwo-pointerseasy-to-understand-by-retur-75o8 | ```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s)\n {\n int n=s.size(),i=0,j=n-1,ans=0;\n int yes=-1;\n while(i | return_7 | NORMAL | 2022-09-06T00:33:10.969680+00:00 | 2022-09-06T00:33:10.969739+00:00 | 736 | false | ```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s)\n {\n int n=s.size(),i=0,j=n-1,ans=0;\n int yes=-1;\n while(i<j)\n {\n if(s[i]!=s[j])\n {\n int temp=j-1;\n while(s[temp]!=s[i])\n temp--;\n ... | 2 | 0 | ['Two Pointers', 'C'] | 0 |
minimum-number-of-moves-to-make-palindrome | C++ | Short and Simple Greedy Solution | c-short-and-simple-greedy-solution-by-dh-awdx | \n\n int minMovesToMakePalindrome(string s) {\n int n = s.size(), ans = 0;\n while(n)\n {\n int i = 0;\n while(s[i | dhakad_g | NORMAL | 2022-08-20T04:54:51.062942+00:00 | 2022-08-20T04:54:51.062987+00:00 | 409 | false | \n```\n int minMovesToMakePalindrome(string s) {\n int n = s.size(), ans = 0;\n while(n)\n {\n int i = 0;\n while(s[i] != s[n-1]) i++;\n if(i == n-1) ans += (n-1)/2;\n else ans += i, s.erase(s.begin()+i),n--;\n s.pop_back();\n n--... | 2 | 0 | ['Greedy', 'C'] | 0 |
minimum-number-of-moves-to-make-palindrome | Easy Two-Pointer C++ method (75% faster) | easy-two-pointer-c-method-75-faster-by-s-2jeo | \n int minMovesToMakePalindrome(string s) {\n int n=s.size();\n int i=0;\n int j=n-1;\n int cnt=0;\n int centre_ele=-1;\n | sxkshi | NORMAL | 2022-08-13T12:26:50.083064+00:00 | 2022-08-17T02:20:58.067126+00:00 | 612 | false | ```\n int minMovesToMakePalindrome(string s) {\n int n=s.size();\n int i=0;\n int j=n-1;\n int cnt=0;\n int centre_ele=-1;\n int left,right;\n while(i<=j)\n {\n //non-matching elements\n if(s[i]!=s[j])\n {\n left=i+1... | 2 | 0 | ['Two Pointers', 'C', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | [Python3] peel the string | python3-peel-the-string-by-ye15-vfaz | \n\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n ans = 0 \n while len(s) > 2: \n lo = s.find(s[-1])\n | ye15 | NORMAL | 2022-06-14T19:50:47.489222+00:00 | 2022-06-14T19:50:47.489331+00:00 | 1,044 | false | \n```\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n ans = 0 \n while len(s) > 2: \n lo = s.find(s[-1])\n hi = s.rfind(s[0])\n if lo < len(s)-hi-1: \n ans += lo \n s = s[:lo] + s[lo+1:-1]\n else: \n ... | 2 | 0 | ['Python3'] | 0 |
minimum-number-of-moves-to-make-palindrome | C++ | TWO-POINTERS | implementation | c-two-pointers-implementation-by-chikzz-2plq | PLEASE UPVOTE IF U LIKE MY SOLUTION AND EXPLANATION :\')\n\n\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n \n int n= | chikzz | NORMAL | 2022-03-07T17:01:44.081160+00:00 | 2022-03-07T17:01:44.081194+00:00 | 237 | false | **PLEASE UPVOTE IF U LIKE MY SOLUTION AND EXPLANATION :\')**\n\n```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n \n int n=s.length();\n int left=0,right=n-1;\n int res=0;\n \n while(left<right)\n {\n int l=left,r=right; \n ... | 2 | 0 | ['Two Pointers'] | 0 |
minimum-number-of-moves-to-make-palindrome | [Python] Easy And Good Solution. | python-easy-and-good-solution-by-laxmina-jud7 | let\'s take one example: let s = "letelt". we have two cases where final s can start with l or final s can end with t. we calculate moves for both of them. for | laxminarayanak | NORMAL | 2022-03-06T02:26:28.003121+00:00 | 2022-03-06T15:24:45.154842+00:00 | 773 | false | **let\'s take one example:** let ```s = "letelt"```. we have two cases where final ```s``` can start with ```l``` or final ```s``` can end with ```t```. we calculate moves for both of them. for final ```s``` starts with ```l``` takes 1 swap(i.e letetl) and for final ```s``` ends with ```t``` takes two swap (i.e tleel... | 2 | 0 | ['Dynamic Programming', 'Greedy', 'Python'] | 0 |
minimum-number-of-moves-to-make-palindrome | Accepted Easy Java Solution | accepted-easy-java-solution-by-himanshus-klcj | \nclass Solution {\n public static boolean isValid(String s) {\n int[] counter = new int[26];\n int oddCount = 0;\n for (int i = 0; i < | himanshushekar | NORMAL | 2022-03-05T16:09:41.227244+00:00 | 2022-03-05T16:10:59.357890+00:00 | 473 | false | \nclass Solution {\n public static boolean isValid(String s) {\n int[] counter = new int[26];\n int oddCount = 0;\n for (int i = 0; i < s.length(); i++) {\n counter[s.charAt(i) - \'a\']++;\n }\n for (int value : counter) {\n if (value % 2 != 0) {\n ... | 2 | 3 | ['Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | Segment tree Solution | O(NLogN) | segment-tree-solution-onlogn-by-viditgup-pep7 | IntuitionI am assuming you are aware with how this could be solved using the brute way in O(n^2). The main problem with that approach is to track the indices af | viditgupta7001 | NORMAL | 2025-03-08T21:38:34.079979+00:00 | 2025-03-08T21:38:34.079979+00:00 | 59 | false | # Intuition
I am assuming you are aware with how this could be solved using the brute way in O(n^2). The main problem with that approach is to track the indices after making swaps. If we are somehow able to track the correct position of indices, we can find the first occurence of a character to the left or right of an ... | 1 | 0 | ['Two Pointers', 'Greedy', 'Segment Tree', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | Simple two pointer approach || edge case explained | simple-two-pointer-approach-edge-case-ex-vqb7 | IntuitionApproachUsing two pointers to check each character from start and end of string.Edge CaseIn case a string is of odd length, there can be one character | sakshecodes | NORMAL | 2024-12-02T06:25:53.097767+00:00 | 2024-12-14T16:29:12.102068+00:00 | 185 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUsing two pointers to check each character from start and end of string.\n\n# Edge Case\nIn case a string is of odd length, there can be one character (center character), which will not have a duplicate in the string.\nUsing... | 1 | 0 | ['Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | Easy Approach!! With Explanation !! Upvote | easy-approach-with-explanation-upvote-by-js9d | 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 | Pratheesha | NORMAL | 2024-08-28T18:38:37.606576+00:00 | 2024-08-28T18:38:37.606608+00:00 | 17 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n \nint minMovesToMakePalindrome(string s) {... | 1 | 0 | ['C', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | ✅Easy C++ Soln || With Explanation || Optimized Soln || Two-Pointers || With Comments | easy-c-soln-with-explanation-optimized-s-2s7g | \n int minMovesToMakePalindrome(string s) {\n \n int st = 0, end = s.length()-1,ans=0;\n \n while(st<end){\n \n | tanishsingla13390 | NORMAL | 2024-06-11T11:53:57.589071+00:00 | 2024-06-11T11:53:57.589103+00:00 | 33 | false | ```\n int minMovesToMakePalindrome(string s) {\n \n int st = 0, end = s.length()-1,ans=0;\n \n while(st<end){\n \n int l = st, r = end;\n \n // if first and last elements are not equal\n // then we will move until we find the equal element... | 1 | 0 | ['Greedy', 'C', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | Python (Simple Greedy) | python-simple-greedy-by-rnotappl-jjhe | 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 | rnotappl | NORMAL | 2024-05-23T12:45:36.444885+00:00 | 2024-05-23T12:45:36.444915+00:00 | 422 | 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 |
minimum-number-of-moves-to-make-palindrome | Java Optimize Solution with Some Minute Explanation | Interview Tricky Question | java-optimize-solution-with-some-minute-0fes2 | Complexity\n- Time complexity:O(n*k)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | Shree_Govind_Jee | NORMAL | 2024-02-06T03:33:50.888374+00:00 | 2024-02-06T03:33:50.888392+00:00 | 364 | false | # Complexity\n- Time complexity:$$O(n*k)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n private int helper(char[] ch, int left, int temp) {\n while (left < temp) {\n i... | 1 | 0 | ['Two Pointers', 'String', 'Greedy', 'Binary Indexed Tree', 'Java'] | 1 |
minimum-number-of-moves-to-make-palindrome | JS solution - Greedy + Merge Sort | js-solution-greedy-merge-sort-by-cutetn-buqm | \n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\nLike, seriously, how solutions with slice and split have better time smh that\'s weir | CuteTN | NORMAL | 2024-01-13T20:34:28.998468+00:00 | 2024-01-13T20:34:28.998497+00:00 | 310 | false | \n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\nLike, seriously, how solutions with `slice` and `split` have better time smh that\'s weird.\n\n# Complexity\n- let `n = s.length`; ... | 1 | 0 | ['Two Pointers', 'String', 'Greedy', 'Merge Sort', 'JavaScript'] | 0 |
minimum-number-of-moves-to-make-palindrome | C++ || Two Pointers || Greedy | c-two-pointers-greedy-by-nithish_9-xsdl | \n\n# Code\n\nclass Solution {\npublic:\n \n int minMovesToMakePalindrome(string s) {\n \n int low = 0;\n int high = s.length()-1;\n\ | Nithish_9 | NORMAL | 2023-08-07T07:10:56.430792+00:00 | 2023-08-07T07:10:56.430824+00:00 | 53 | false | \n\n# Code\n```\nclass Solution {\npublic:\n \n int minMovesToMakePalindrome(string s) {\n \n int low = 0;\n int high = s.length()-1;\n\n int count = 0;\n while (low<=high)\n {\n if (s[low] != s[high])\n {\n int i = high-1;\n ... | 1 | 0 | ['Two Pointers', 'Greedy', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | Straightforward Greedy Algorithm in Python, Beating 100% | straightforward-greedy-algorithm-in-pyth-o82i | Approach\n Describe your approach to solving the problem. \nIn each turn, it is necessary to match the first character s[0] and the last charactor s[-1] of the | metaphysicalist | NORMAL | 2023-07-07T03:57:23.834551+00:00 | 2023-07-07T03:59:19.121850+00:00 | 115 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nIn each turn, it is necessary to match the first character `s[0]` and the last charactor `s[-1]` of the string `s`. Do nothing if the first and the last ones already match (i.e., `s[0] == s[-1]`). Otherwise, my greedy approach determines to replace th... | 1 | 0 | ['String', 'Greedy', 'Python3'] | 1 |
minimum-number-of-moves-to-make-palindrome | Straightforward Brute-Force in Python, Beating 100% | straightforward-brute-force-in-python-be-1c8u | Approach\n Describe your approach to solving the problem. \nIn each turn, it is necessary to match the first character s[0] and the last charactor s[-1] of the | metaphysicalist | NORMAL | 2023-07-06T05:10:50.705405+00:00 | 2023-07-06T05:11:23.836018+00:00 | 203 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nIn each turn, it is necessary to match the first character `s[0]` and the last charactor `s[-1]` of the string `s`. Do nothing if the first and the last ones already match (i.e., `s[0] == s[-1]`). Otherwise, my greedy approach determines to replace th... | 1 | 0 | ['Two Pointers', 'String', 'Python3'] | 1 |
minimum-number-of-moves-to-make-palindrome | simple iterative solution | simple-iterative-solution-by-zaidokhla-mzng | Intuition\nin each iteration of the while loop(outer) we are solving a subproblem or trying to make the chars to be equal \nfor that we can either swap the s[l] | zaidokhla | NORMAL | 2023-04-27T08:56:41.996373+00:00 | 2023-04-27T08:56:41.996413+00:00 | 431 | false | # Intuition\nin each iteration of the while loop(outer) we are solving a subproblem or trying to make the chars to be equal \nfor that we can either swap the s[l] to next similar char on the right which is equal to s[r]\nor we can swap s[r] we the next similar char on the left which is equal to s[l] \neither way would ... | 1 | 0 | ['C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | Full proof O(n) and O(1) C++ solution with in depth explaination | full-proof-on-and-o1-c-solution-with-in-2jw00 | Intuition\nSo the intuition behind this is that, if we can make the extreme elements (first and last index elements) of the string a palindrome taking optimal m | nutan_sangani | NORMAL | 2023-01-03T07:55:20.401804+00:00 | 2023-01-03T07:55:20.401855+00:00 | 98 | false | # Intuition\nSo the intuition behind this is that, if we can make the extreme elements (first and last index elements) of the string a palindrome taking optimal moves than we can recurse the algorithm on the substring from 2nd and 2nd last index, and so on and repeating this we can find the optimal no of moves.\n\nBut ... | 1 | 0 | ['Two Pointers', 'String', 'Greedy', 'C++'] | 0 |
minimum-number-of-moves-to-make-palindrome | best solution | best-solution-by-riyuzaki7-j7uo | 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 | Riyuzaki7 | NORMAL | 2022-12-23T13:47:27.385787+00:00 | 2022-12-23T13:47:27.385825+00:00 | 102 | 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 |
minimum-number-of-moves-to-make-palindrome | Python + 2 pointers + Explanation. | python-2-pointers-explanation-by-rasnouk-ymjq | \n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n # At each point, we | rasnouk | NORMAL | 2022-11-13T22:46:16.709243+00:00 | 2022-11-13T22:46:16.709289+00:00 | 937 | false | \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n # At each point, we look at the first and the last elements\n # if they are the same, then we skip them, else we find\n # another element in the string ... | 1 | 0 | ['Python3'] | 0 |
minimum-number-of-moves-to-make-palindrome | [Java Easy Solution w/ Comments] - Using Two Pointer Swapping | java-easy-solution-w-comments-using-two-nkr4w | Intuition\nJava Solution to Minimum Number of Moves To Make Palindrome. Uses a Two Pointer approach with swapping.\n\nIncluded comments for reference.\n\n# Comp | bjornmelin | NORMAL | 2022-10-03T22:02:57.139259+00:00 | 2022-10-03T22:02:57.139304+00:00 | 215 | false | # Intuition\nJava Solution to Minimum Number of Moves To Make Palindrome. Uses a Two Pointer approach with swapping.\n\nIncluded comments for reference.\n\n# Complexity\n- Time complexity: $$O(N^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N)$$\n<!-- Add your space complexity h... | 1 | 0 | ['Two Pointers', 'String', 'Binary Indexed Tree', 'Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | [Rust] Simple greedy solution | rust-simple-greedy-solution-by-wizist-ne1q | For any string with length > 1, check the number of moves required to make the string with equal leftmost and rightmost characters. Remove the leftmost and the | wizist | NORMAL | 2022-09-23T13:47:34.791451+00:00 | 2022-09-23T13:47:34.791494+00:00 | 300 | false | For any string with length > 1, check the number of moves required to make the string with equal leftmost and rightmost characters. Remove the leftmost and the rightmost characters. Repeat the procedure until the string length less than or equal to 1. The sum of all moves is the answer.\n\n```rust\nuse std::collections... | 1 | 0 | ['Greedy', 'Rust'] | 0 |
minimum-number-of-moves-to-make-palindrome | [python3] easy to understand 2 pointer solution with comments | python3-easy-to-understand-2-pointer-sol-dsfb | \n\'\'\'\nidea is to fix one side (left or right) and make other side equal to it\nfor e.g. \naabb , I will make right side equal to left.\n1. index[0] = a != i | kakarotssj11 | NORMAL | 2022-09-21T07:59:03.218578+00:00 | 2022-09-21T07:59:03.218616+00:00 | 654 | false | ```\n\'\'\'\nidea is to fix one side (left or right) and make other side equal to it\nfor e.g. \naabb , I will make right side equal to left.\n1. index[0] = a != index[3] = b \n2. now look for a from right to left \n3. once found swap with adjacent element till it reaches index[3].\n4. abba. is palindrome. took 2 swaps... | 1 | 0 | ['Two Pointers', 'Python3'] | 0 |
minimum-number-of-moves-to-make-palindrome | java solution | java-solution-by-mrvishal_27-7xpc | \nclass Solution {\n public int minMovesToMakePalindrome(String s) {\n int ans=0;\n char arr[]=s.toCharArray();\n int i=0; \n int | MrVishal_27 | NORMAL | 2022-09-20T23:54:17.730441+00:00 | 2022-09-20T23:54:17.730481+00:00 | 868 | false | ```\nclass Solution {\n public int minMovesToMakePalindrome(String s) {\n int ans=0;\n char arr[]=s.toCharArray();\n int i=0; \n int j=arr.length-1;\n while(i<j){\n int high=j;\n if(arr[i]==arr[j]){\n i++;\n j--;\n }\n ... | 1 | 0 | ['Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | Python 2 pointer approach | python-2-pointer-approach-by-hemantdhami-mgui | \nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s = list(s)\n res, left, right = 0, 0, len(s) - 1\n while left | hemantdhamija | NORMAL | 2022-09-05T07:23:38.366594+00:00 | 2022-09-05T07:23:38.366629+00:00 | 468 | false | ```\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s = list(s)\n res, left, right = 0, 0, len(s) - 1\n while left < right:\n l, r = left, right\n while s[l] != s[r]:\n r -= 1\n if l == r:\n s[r], s[r + 1] = s... | 1 | 0 | ['Two Pointers', 'Greedy', 'Python'] | 0 |
minimum-number-of-moves-to-make-palindrome | [C++] Simple C++ Code | c-simple-c-code-by-prosenjitkundu760-0i3h | Taken the help by master piece submission by\nhttps://leetcode.com/be_quick/\n\n# If you like the implementation then Please help me by increasing my reputation | _pros_ | NORMAL | 2022-09-03T18:13:18.636174+00:00 | 2022-09-03T18:14:02.281016+00:00 | 272 | false | **Taken the help by master piece submission by**\nhttps://leetcode.com/be_quick/\n\n# **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int i = 0, j ... | 1 | 0 | ['Two Pointers', 'Greedy', 'C'] | 0 |
minimum-number-of-moves-to-make-palindrome | C# solution | c-solution-by-clewby-k7ys | \npublic class Solution {\n public int MinMovesToMakePalindrome(string s) {\n List<char> list = s.ToList();\n int moves = 0;\n while(lis | clewby | NORMAL | 2022-09-01T06:16:36.524592+00:00 | 2022-11-04T18:54:52.325701+00:00 | 151 | false | ```\npublic class Solution {\n public int MinMovesToMakePalindrome(string s) {\n List<char> list = s.ToList();\n int moves = 0;\n while(list.Count > 2){\n char target = list[0];\n int i = list.FindLastIndex(ch => ch == target);\n if(i != 0){\n move... | 1 | 0 | ['Greedy'] | 0 |
minimum-number-of-moves-to-make-palindrome | Java | O(NlogN) | Harder Variant of 1505. | java-onlogn-harder-variant-of-1505-by-st-ylrk | This question is the harder version of #1505 (link), so I can recommend that you do that problem first before coming back to this one. The idea is basically the | Student2091 | NORMAL | 2022-08-09T00:19:27.327582+00:00 | 2022-08-09T00:20:08.196018+00:00 | 725 | false | This question is the harder version of [#1505 (link)](https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits), so I can recommend that you do that problem first before coming back to this one. The idea is basically the same - to know what its actual position is, we need the pref... | 1 | 0 | ['Java'] | 0 |
minimum-number-of-moves-to-make-palindrome | Python simple recursion | 97% time | python-simple-recursion-97-time-by-dyc_9-ewac | \n def minMovesToMakePalindrome(self, s: str) -> int:\n n = len(s)\n if n <= 1:\n return 0\n if s[0]==s[-1]:\n ret | dyc_98 | NORMAL | 2022-08-05T21:51:03.190541+00:00 | 2022-08-05T21:51:03.190567+00:00 | 979 | false | ```\n def minMovesToMakePalindrome(self, s: str) -> int:\n n = len(s)\n if n <= 1:\n return 0\n if s[0]==s[-1]:\n return self.minMovesToMakePalindrome(s[1:-1])\n \n ind_l, ind_r = s.find(s[-1]), s.rfind(s[0])\n if ind_l <= n-1-ind_r:\n return... | 1 | 0 | ['Greedy', 'Recursion', 'Python'] | 0 |
minimum-number-of-moves-to-make-palindrome | [C++] Two pointers approach | Easy to Understand | c-two-pointers-approach-easy-to-understa-h26h | \nclass Solution {\npublic:\n /*\n Two cases can come\n while we can compare first half with other half\n case 1 aabb -> a != b come back and se | amitesh46237242 | NORMAL | 2022-07-09T16:50:56.579591+00:00 | 2022-07-09T16:50:56.579619+00:00 | 264 | false | ```\nclass Solution {\npublic:\n /*\n Two cases can come\n while we can compare first half with other half\n case 1 aabb -> a != b come back and see if we find a , we finally find an \'a\' at aa so swap it till we bring it at end to match , abab swap again abba, now a==a now its turn of b and its matchi... | 1 | 0 | ['Two Pointers', 'C'] | 0 |
minimum-number-of-moves-to-make-palindrome | C++ Easy Solution | Greedy | c-easy-solution-greedy-by-rac101ran-or9o | \nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int cnt = 0;\n while(!s.empty()) {\n int other = s.find( | rac101ran | NORMAL | 2022-07-07T01:17:09.120460+00:00 | 2022-07-07T01:17:09.120506+00:00 | 253 | false | ```\nclass Solution {\npublic:\n int minMovesToMakePalindrome(string s) {\n int cnt = 0;\n while(!s.empty()) {\n int other = s.find(s.back());\n if(other==s.size()-1) {\n // odd ?\n cnt+=other/2; // move it to the middle \n }el... | 1 | 0 | ['Greedy', 'C'] | 0 |
minimum-number-of-moves-to-make-palindrome | USING TWO POINTER || SIMPLEST SOLUTION | using-two-pointer-simplest-solution-by-k-bdey | \n int i=0;\n int j=s.size()-1;\n int l=0;\n int r=s.size()-1;\n int cnt=0;\n while(l<r){\n if(s[l]==s[r])\n | kranti1 | NORMAL | 2022-06-24T14:52:04.189288+00:00 | 2022-06-24T14:52:04.189325+00:00 | 320 | false | ```\n int i=0;\n int j=s.size()-1;\n int l=0;\n int r=s.size()-1;\n int cnt=0;\n while(l<r){\n if(s[l]==s[r])\n {\n l++;\n r--;\n continue;\n }\n i=l;\n j=r;\n while(s[j]!=s[... | 1 | 0 | ['C'] | 0 |
minimum-number-of-moves-to-make-palindrome | Python || 2 Pointers || Greddy | python-2-pointers-greddy-by-in_sidious-77bf | Make first half equal to second half greedily!!\n\n\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n n=len(s)\n s=list(s | iN_siDious | NORMAL | 2022-06-03T14:05:26.374973+00:00 | 2022-06-03T14:05:26.375006+00:00 | 801 | false | Make first half equal to second half greedily!!\n\n```\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n n=len(s)\n s=list(s)\n l,r=0,n-1\n ans=0\n while (l<r):\n ll,rr=l,r\n while (s[ll]!=s[rr]): rr-=1\n if (ll==rr): ... | 1 | 0 | ['Greedy', 'Python'] | 0 |
minimum-number-of-moves-to-make-palindrome | Very Easy Solution With Proper Comments | C++ | very-easy-solution-with-proper-comments-8wd1n | \nclass Solution {\npublic:\n \n /**\n \n observation->we only need to move one of two characters of the palindrome string at minimum cost\n \n | sumer47kumar | NORMAL | 2022-05-22T14:31:51.886209+00:00 | 2022-05-22T14:31:51.886263+00:00 | 637 | false | ```\nclass Solution {\npublic:\n \n /**\n \n observation->we only need to move one of two characters of the palindrome string at minimum cost\n \n \n move from left to right\n try to find and swap the character according scanning from right to left\n -> from required position to l... | 1 | 0 | ['Greedy', 'C', 'C++'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.