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
minimum-insertion-steps-to-make-a-string-palindrome
Image Explanation🏆- [Recursion -> Top Down -> Bottom Up -> Bottom Up O(n)] - C++/Java/Python
image-explanation-recursion-top-down-bot-3ywf
Video Solution (Aryan Mittal) - Link in LeetCode Profile\nMinimum Insertion Steps to Make a String Palindrome by Aryan Mittal\n\n\n\n# Longest Palindromic Subse
aryan_0077
NORMAL
2023-04-22T01:15:28.090212+00:00
2023-04-22T01:30:51.571112+00:00
5,554
false
# Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\n`Minimum Insertion Steps to Make a String Palindrome` by `Aryan Mittal`\n![lc.png](https://assets.leetcode.com/users/images/049c3374-1bdd-4426-b961-2f988c034e8e_1682126946.7610044.png)\n\n\n# [Longest Palindromic Subsequence - LPS](https://leetcode.com/probl...
20
2
['String', 'Dynamic Programming', 'C++', 'Java', 'Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
100% memory efficient and 98% faster solution.[EASY] | [C++] | [DP] | [LCS]
100-memory-efficient-and-98-faster-solut-mulc
TOP-DOWN DYNAMIC PROGRAMING\nWe need to find if there exist any subsequence of string S1 which is palindrome. \nIf there is such a subsequence sub, then we need
sonukumarsaw
NORMAL
2020-05-15T16:41:58.104929+00:00
2020-05-15T16:41:58.104984+00:00
2,447
false
**TOP-DOWN DYNAMIC PROGRAMING**\nWe need to find if there exist any subsequence of string **S1** which is palindrome. \nIf there is such a subsequence **sub**, then we need minimum ***len(S1)-len(sub)***\nElse, we need atleast ***len(S1)*** number of insertions to make it palindrome.\n\nTo find the len of subsequence o...
19
1
['Dynamic Programming', 'C']
2
minimum-insertion-steps-to-make-a-string-palindrome
Python Clean DP
python-clean-dp-by-wangqiuc-ru1r
dp[i,j] stands for the minimum insertion steps to make s[i:j+1] palindrome.\nIf s[i] == s[j] then dp[i,j] should be equal to dp[i+1,j-1] as no extra cost needed
wangqiuc
NORMAL
2020-01-11T05:11:45.565362+00:00
2020-01-11T15:10:43.192848+00:00
2,550
false
`dp[i,j]` stands for the minimum insertion steps to make `s[i:j+1]` palindrome.\nIf `s[i] == s[j]` then `dp[i,j]` should be equal to `dp[i+1,j-1]` as no extra cost needed for a palidrome string to include `s[i]` on the left and `s[j]` on the right. \nOtherwise, `dp[i,j]` take an extra 1 cost from the smaller cost betwe...
17
0
['Python']
3
minimum-insertion-steps-to-make-a-string-palindrome
DP🫡| Simple Java Solution | Longest Palindromic Subsequence
dp-simple-java-solution-longest-palindro-5vec
Intuition\nIf we know the longest palindromic sub-sequence is x and the length of the string is n then, what is the answer to this problem? It is n - x as we ne
Comrade-in-code
NORMAL
2023-03-19T05:20:25.013710+00:00
2023-03-19T05:20:25.013758+00:00
1,939
false
# Intuition\nIf we know the **longest palindromic sub-sequence** is x and the length of the string is n then, what is the answer to this problem? It is n - x as we need n - x insertions to make the remaining characters also palindrome.\n\n# Approach\nWe just need to find the length of **longest common subsequence** of ...
15
0
['String', 'Dynamic Programming', 'Java']
2
minimum-insertion-steps-to-make-a-string-palindrome
[Javascript] Dynamic Programming Easy and explained
javascript-dynamic-programming-easy-and-ao630
Explanation : This is the direct implementation of Longest Palindromic Subsequence. \n\nPS: Feel free to ask your questions in comments and do upvote if you lik
dhairyabahl
NORMAL
2021-09-02T13:51:16.547121+00:00
2021-09-02T13:51:16.547186+00:00
1,117
false
**Explanation** : This is the direct implementation of Longest Palindromic Subsequence. \n\nPS: Feel free to ask your questions in comments and do upvote if you liked my solution.\n\n```\n/**\n * @param {string} s\n * @return {number}\n */\nvar minInsertions = function(s) {\n \n let dp = []\n \n for(let row...
14
0
['Dynamic Programming', 'JavaScript']
1
minimum-insertion-steps-to-make-a-string-palindrome
= longest palindrome subsequence
longest-palindrome-subsequence-by-hobite-rhbk
I know there are a lot of BIG GOD\'s discussions to show how to solve this. \nBut for easy understanding, this problem could be transformed to:\nFinding "longes
hobiter
NORMAL
2020-01-08T06:01:38.794667+00:00
2020-01-08T06:12:40.658149+00:00
1,668
false
I know there are a lot of BIG GOD\'s discussions to show how to solve this. \nBut for easy understanding, this problem could be transformed to:\n**Finding "longest palindrome subsequence", **\nthen transformed to:\n**Finding "longest common subsequence to his reversed string ".**\n```\ninInsertions(String s) \n= n - lo...
14
2
[]
5
minimum-insertion-steps-to-make-a-string-palindrome
Easy Solution Of JAVA 🔥C++ 🔥DP 🔥Beginner Friendly
easy-solution-of-java-c-dp-beginner-frie-jwyi
\n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n public int minInsertions(String s) {\n StringBuilder sb = new StringBuilder(s);\n
shivrastogi
NORMAL
2023-04-22T01:02:08.268318+00:00
2023-04-22T01:02:08.268341+00:00
2,539
false
\n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n public int minInsertions(String s) {\n StringBuilder sb = new StringBuilder(s);\n sb.reverse();\n String rev = sb.toString();\n int n = s.length();\n int[][] dp = new int[n+1][n+1];\n for(int i=1;i<=n;i++) {...
13
6
['Dynamic Programming', 'C++', 'Java']
1
minimum-insertion-steps-to-make-a-string-palindrome
How (len - LPS)??? Explained with images || Recursion to Bottom UP
how-len-lps-explained-with-images-recurs-zvh1
\n\n\n\n## RECURSION\n\nclass Solution {\npublic:\n int lps(string& s, int start, int end)\n {\n if (start == end) return 1;\n if (start > e
mohakharjani
NORMAL
2023-04-22T00:40:34.354812+00:00
2023-04-22T00:42:32.950525+00:00
692
false
![image](https://assets.leetcode.com/users/images/84f65bac-e8cd-4634-bf72-0b7685762631_1682124024.6771638.jpeg)\n![image](https://assets.leetcode.com/users/images/ad5faf88-fff6-4085-93a8-82ee9b1e28d6_1682124031.7868736.jpeg)\n\n\n## RECURSION\n```\nclass Solution {\npublic:\n int lps(string& s, int start, int end)\n...
12
1
['Dynamic Programming', 'C', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Day 112 || Recursion > Memoization || Easiest Beginner Friendly Sol
day-112-recursion-memoization-easiest-be-77kp
NOTE - PLEASE READ INTUITION AND APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.\n\n# Intuitio
singhabhinash
NORMAL
2023-04-22T00:39:35.748863+00:00
2023-04-22T00:46:53.537589+00:00
1,870
false
**NOTE - PLEASE READ INTUITION AND APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n\n# Intuition of this Problem :\n**If you know how to solve Longest palindromic Subsequence then this problem is easy for you. For example s = "acdsddca" then longest p...
11
0
['Recursion', 'Memoization', 'C++']
3
minimum-insertion-steps-to-make-a-string-palindrome
JAVA || DP - 1D and 2D || Beats 70% Time & 100% Space || Explanation || Space optimization
java-dp-1d-and-2d-beats-70-time-100-spac-i5v6
Intuition\n Describe your first thoughts on how to solve this problem. \nTo make a given string palindrome, we need to insert some characters at some positions.
millenium103
NORMAL
2023-04-22T05:23:55.286519+00:00
2023-04-22T05:23:55.286550+00:00
1,660
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo make a given string palindrome, we need to insert some characters at some positions. If we can find out the longest common subsequence between the given string and its reverse, we can find out the characters that don\'t need to be inse...
10
0
['String', 'Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Longest Palindromic Subsequence | Aditya Verma's approach
longest-palindromic-subsequence-aditya-v-dnt7
Just find the length of Longest Palindromic Subsequence and subtract it from the string size (in the same way we can calculate "minimum number of deletions to m
iashi_g
NORMAL
2021-06-29T06:56:52.643842+00:00
2021-06-29T06:56:52.643888+00:00
928
false
Just find the length of Longest Palindromic Subsequence and subtract it from the string size (in the same way we can calculate "minimum number of deletions to make a string palindrome").\n```\nclass Solution {\npublic:\n int lcs(int x, int y, string s1, string s2)\n {\n int dp[x+1][y+1];\n \n ...
10
0
['Dynamic Programming', 'C']
1
minimum-insertion-steps-to-make-a-string-palindrome
simple python DP solution: longest common subsequence variation.
simple-python-dp-solution-longest-common-w8gg
Let the first string be a. then take a new string b which is reversed of a.\napply longest common subsequnce on both the strings and subtract the answer from th
captain_levi
NORMAL
2020-08-04T04:42:28.464618+00:00
2020-08-04T04:42:28.464653+00:00
1,386
false
Let the first string be a. then take a new string b which is reversed of a.\napply longest common subsequnce on both the strings and subtract the answer from the length of the string.\nit works for minimum number of deletion as well as minimum number of insertion to make a string palindrome.\n\n\tclass Solution:\n\t\td...
9
0
['Dynamic Programming', 'Python', 'Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
[JAVA] Simple DP with explanation and very small code
java-simple-dp-with-explanation-and-very-ovd1
The initution is two pointers (at the beginning and at the end end).\n2. Match the the pointer if the match move the pointers(begin+1 and end-1)\n3. If they don
siddhantiitbmittal3
NORMAL
2020-01-07T14:39:59.251430+00:00
2020-01-07T14:39:59.251478+00:00
867
false
1. The initution is two pointers (at the beginning and at the end end).\n2. Match the the pointer if the match move the pointers(begin+1 and end-1)\n3. If they dont match either you add character at the end or character at the begin. \n4. Since we have a choice here if have to make the min of the two cases. Thus formin...
9
0
[]
2
minimum-insertion-steps-to-make-a-string-palindrome
"one-liner"
one-liner-by-stefanpochmann-q1rr
\nfrom functools import lru_cache\n\nclass Solution:\n @lru_cache(None)\n def minInsertions(self, s):\n return(n:=len(s))and 1-(e:=s[0]==s[-1])+min
stefanpochmann
NORMAL
2020-01-05T14:47:07.928109+00:00
2020-01-05T14:49:17.825939+00:00
660
false
```\nfrom functools import lru_cache\n\nclass Solution:\n @lru_cache(None)\n def minInsertions(self, s):\n return(n:=len(s))and 1-(e:=s[0]==s[-1])+min(map(self.minInsertions,(s[e:-1],s[1:n-e])))\n```
9
5
[]
0
minimum-insertion-steps-to-make-a-string-palindrome
Python3 short straight forward DP
python3-short-straight-forward-dp-by-kai-mloo
\nimport functools\nclass Solution:\n def minInsertions(self, s: str) -> int:\n @functools.lru_cache(None)\n def dp(i, j):\n if j -
kaiwensun
NORMAL
2020-01-05T04:11:21.054250+00:00
2020-01-05T04:22:45.655215+00:00
1,285
false
```\nimport functools\nclass Solution:\n def minInsertions(self, s: str) -> int:\n @functools.lru_cache(None)\n def dp(i, j):\n if j - i <= 1: return 0\n return dp(i + 1, j - 1) if s[i] == s[j - 1] else min(dp(i + 1, j), dp(i, j - 1)) + 1\n return dp(0, len(s))\n```
9
1
[]
1
minimum-insertion-steps-to-make-a-string-palindrome
C# | Runtime beats 91.07%, Memory beats 82.14% [EXPLAINED]
c-runtime-beats-9107-memory-beats-8214-e-0hdy
Intuition\nTo make a string a palindrome, you can think of adding characters to balance it out. A palindrome reads the same forwards and backwards. If some char
r9n
NORMAL
2024-09-19T20:20:08.389681+00:00
2024-09-19T20:20:08.389700+00:00
41
false
# Intuition\nTo make a string a palindrome, you can think of adding characters to balance it out. A palindrome reads the same forwards and backwards. If some characters don\u2019t match, we need to add characters to make them match, which means we need to figure out how many additions are necessary.\n\n# Approach\nDyna...
8
0
['Two Pointers', 'Matrix', 'C#']
0
minimum-insertion-steps-to-make-a-string-palindrome
[Kotlin] Minimum code to solve with DFS + memo
kotlin-minimum-code-to-solve-with-dfs-me-2ekm
\n fun minInsertions(s: String): Int {\n val cache = Array(s.length) { IntArray(s.length) { -1 } }\n \n fun dfs(l: Int, r: Int): Int {\n
dzmtr
NORMAL
2023-04-22T10:06:37.229523+00:00
2023-04-22T10:06:37.229564+00:00
34
false
```\n fun minInsertions(s: String): Int {\n val cache = Array(s.length) { IntArray(s.length) { -1 } }\n \n fun dfs(l: Int, r: Int): Int {\n if (l > r) return 0\n if (cache[l][r] != -1) return cache[l][r]\n\n cache[l][r] = if (s[l] == s[r]) {\n dfs(...
8
0
['Dynamic Programming', 'Kotlin']
0
minimum-insertion-steps-to-make-a-string-palindrome
C++ | Clean Code (25 lines) | Easy to understand | Well explained
c-clean-code-25-lines-easy-to-understand-srrc
\n## Pls upvote the thread if you found it helpful.\n\n# Intuition\n Describe your first thoughts on how to solve this problem.l \nIn order to minimize the ins
forkadarshp
NORMAL
2023-04-22T01:12:10.462849+00:00
2023-04-22T15:13:54.662892+00:00
3,008
false
\n## **Pls upvote the thread if you found it helpful.**\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem.l --> \nIn order to minimize the insertions, we need to find the **difference** of length of the longest palindromic subsequence and string length. \n\n`Minimum Insertion required = len...
8
0
['String', 'Dynamic Programming', 'C', 'C++']
1
minimum-insertion-steps-to-make-a-string-palindrome
Top-Down Approach (DP)
top-down-approach-dp-by-kunal_kumar_1-pfmm
Intuition\n Describe your first thoughts on how to solve this problem. \nThis question is a variation of longest palindromic subsequence(Q.no- 516).\n# Approach
Kunal_Kumar_1
NORMAL
2023-07-09T09:33:48.384152+00:00
2023-07-09T09:33:48.384173+00:00
37
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis question is a **variation of longest palindromic subsequence**(Q.no- 516).\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFind the length of LCS of given string and it\'s reverse. The **difference of the length...
6
0
['C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Striver Bhaiya 😎 Chad Approach🦸‍♂️ | Woh Bhi Space Optimized 🚀
striver-bhaiya-chad-approach-woh-bhi-spa-u57y
\nclass Solution {\n public int minInsertions(String s1) {\n\t int n =s1.length();\n String s2 ="";\n for(int i=n-1; i>=0; i--) s2 += s1.cha
rohits05
NORMAL
2023-04-25T08:59:53.829270+00:00
2023-04-25T09:29:21.201169+00:00
206
false
```\nclass Solution {\n public int minInsertions(String s1) {\n\t int n =s1.length();\n String s2 ="";\n for(int i=n-1; i>=0; i--) s2 += s1.charAt(i); // S2 = rev(S1) for L.P.S computation\n \n int dp[] = new int[n+1];\n for(int i=1; i<=n; i++){ // Generating L.C.S ~ Space Optim...
6
0
['Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
C++ | Extra Small | Dynamic Programming | String
c-extra-small-dynamic-programming-string-gn9x
Intuition\n Describe your first thoughts on how to solve this problem. \nDynamic programming\n# Approach\n Describe your approach to solving the problem. \n s
Rishikeshsahoo_2828
NORMAL
2023-04-22T18:04:03.761807+00:00
2023-04-22T18:04:03.761850+00:00
453
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDynamic programming\n# Approach\n<!-- Describe your approach to solving the problem. -->\n size of string - the Longest Palindromic Subsequence\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n ...
6
0
['C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Simple Dp solution based on Longest common subsequence (LCS) Pattern
simple-dp-solution-based-on-longest-comm-f9uu
In lcs code we require 2 string inputs, here we have only 1 string input so we reverse it to get other string. After that we simply write our lcs code.\nFor bet
priyesh_raj_singh
NORMAL
2022-07-30T15:26:51.433944+00:00
2022-07-30T15:28:13.626331+00:00
393
false
In lcs code we require 2 string inputs, here we have only 1 string input so we reverse it to get other string. After that we simply write our lcs code.\nFor better understanding of patterns in DP you can refer to **Aditya Verma\'s Playlist**:- \nhttps://www.youtube.com/playlist?list=PL_z_8CaSLPWekqhdCPmFohncHwz8TY2Go\n...
6
0
[]
1
minimum-insertion-steps-to-make-a-string-palindrome
Java/C++ concise solution
javac-concise-solution-by-vp-1e07
This is a direct implementation of longest palindromic subsequence. \n\n\nclass Solution {\n public String reverseIt(String str)\n {\n int i, le
Vp-
NORMAL
2021-09-02T13:53:33.625999+00:00
2021-09-02T13:53:33.626048+00:00
670
false
This is a direct implementation of longest palindromic subsequence. \n\n```\nclass Solution {\n public String reverseIt(String str)\n {\n int i, len = str.length();\n \n StringBuilder dest = new StringBuilder(len);\n\n for (i = (len - 1); i >= 0; i--)\n dest.append...
6
0
['C++', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Dyanmic Programming Beats 90% solution with detailed explanation
dyanmic-programming-beats-90-solution-wi-ae3c
The question requires us to breakdown the problem in terms of smaller sub-problem\n\nLet dp be a matrix where dp[i][j] stores the minimum number of insertions r
puff_diddy
NORMAL
2020-09-04T12:15:27.694241+00:00
2020-09-04T12:15:27.694277+00:00
625
false
The question requires us to breakdown the problem in terms of smaller sub-problem\n\nLet dp be a matrix where dp[i][j] stores the minimum number of insertions required to make subtring [i...j] palindromic \n Case -1 s[i] != s[j]\n in this case we have two choices, add a character equal to s[i] at the posi...
6
0
[]
4
minimum-insertion-steps-to-make-a-string-palindrome
Java. Minimum Insertion Steps to Make a String Palindrome.
java-minimum-insertion-steps-to-make-a-s-i6k9
\n\nclass Solution {\n public int longestPalindromeSubseq(String s) {\n char []str = s.toCharArray();\n int [][] answ = new int[s.length() + 1]
red_planet
NORMAL
2023-04-22T16:36:37.018727+00:00
2023-04-22T16:36:37.018756+00:00
1,183
false
\n```\nclass Solution {\n public int longestPalindromeSubseq(String s) {\n char []str = s.toCharArray();\n int [][] answ = new int[s.length() + 1][s.length() + 1];\n int n = s.length();\n for(int i = 0; i < s.length(); i++)\n {\n for (int j = n - 1; j > -1; j--)\n ...
5
0
['Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
C++||Picture Explanation🔥||Recursion-->Memoization 🔥|| With Recursion Tree🔥
cpicture-explanationrecursion-memoizatio-kyq4
Approach\n Describe your approach to solving the problem. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# Complexity\n- Time complexity: O(n^2
kaushikm2k
NORMAL
2023-04-22T01:47:36.135755+00:00
2023-04-22T01:50:53.017829+00:00
827
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n\n![image.png](https://assets.leetcode.com/users/images/50813e57-3459-4f29-bf89-329fe7ac3052_1682127238.8847425.png)\n![image.png](https://assets.leetcode.com/users/images/86dae25f-8ad9-4864-9952-32908c088811_1682127258.409485.png)\n![image.png](https...
5
0
['Dynamic Programming', 'Recursion', 'C++']
1
minimum-insertion-steps-to-make-a-string-palindrome
✅C++ || DP
c-dp-by-chiikuu-vp3h
Code\n\nclass Solution {\npublic:\n int minInsertions(string s) {\n string p=s;\n reverse(s.begin(),s.end());\n int n=s.size();\n
CHIIKUU
NORMAL
2023-04-14T08:10:39.792367+00:00
2023-04-14T08:10:39.792405+00:00
215
false
# Code\n```\nclass Solution {\npublic:\n int minInsertions(string s) {\n string p=s;\n reverse(s.begin(),s.end());\n int n=s.size();\n vector<vector<int>>dp(n+1,vector<int>(n+1,0));\n for(int i=1;i<=n;i++){\n for(int j=1;j<=n;j++){\n if(s[j-1]==p[i-1])dp[i...
5
0
['Dynamic Programming', 'C++']
3
minimum-insertion-steps-to-make-a-string-palindrome
Best O(N*M) Solution
best-onm-solution-by-kumar21ayush03-xivu
Approach\nDP (Bottom Up Approach)\n\n# Complexity\n- Time complexity:\nO(n * m)\n\n- Space complexity:\nO(n * m)\n\n# Code\n\nclass Solution {\nprivate:\n in
kumar21ayush03
NORMAL
2023-03-31T10:14:52.140738+00:00
2023-03-31T10:14:52.140775+00:00
261
false
# Approach\nDP (Bottom Up Approach)\n\n# Complexity\n- Time complexity:\n$$O(n * m)$$\n\n- Space complexity:\n$$O(n * m)$$\n\n# Code\n```\nclass Solution {\nprivate:\n int longestPalindromeSubseq(string s, string t) { \n int n = s.length(); \n vector<vector<int>> dp(n+1, vector<int>(n+1, 0));\n ...
5
0
['C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
✔3 STEPS DP Sol | Asked by AMAZON-GOOGLE-UBER || EXPLANATION & COMPLEXITIES👈
3-steps-dp-sol-asked-by-amazon-google-ub-p3k0
EXPLANATION :-\n1. THIS PROBLEM IS MAINLY EXTENSION OF LPS(Longest Palindromic Subsequence).\n2. MOREOVER, THIS IS A DITTO COPY OF A CLASSICAL QUESTION OF DP KN
vishi_brownSand
NORMAL
2021-07-01T10:15:49.849723+00:00
2021-07-01T14:54:44.093653+00:00
224
false
* ## EXPLANATION :-\n1. **`THIS PROBLEM IS MAINLY EXTENSION OF LPS(Longest Palindromic Subsequence).`**\n2. **`MOREOVER, THIS IS A DITTO COPY OF A CLASSICAL QUESTION OF DP KNOWN AS MINIMUM NUMBER OF DELETION TO MAKE A STRING PALINDROME.`**\n3. **`IDEA : In this problem we just have to find LPS of the given string and s...
5
0
['Dynamic Programming']
1
minimum-insertion-steps-to-make-a-string-palindrome
C++ SIMPLE EASY SOLUTION
c-simple-easy-solution-by-chase_master_k-2svh
\nvector<vector<int>> memo;\n //code explained below ...\n int dp(string &s,int i,int j)\n {\n if(i>=j)\t\t//Base case.\n return 0;\n
chase_master_kohli
NORMAL
2020-01-11T07:04:25.667825+00:00
2020-01-11T07:04:50.987308+00:00
606
false
```\nvector<vector<int>> memo;\n //code explained below ...\n int dp(string &s,int i,int j)\n {\n if(i>=j)\t\t//Base case.\n return 0;\n if(memo[i][j]!=-1) //Check if already calculated the value for the pair `i` and `j`.\n return memo[i][j];\n return memo[i][j]=s[i]=...
5
0
[]
1
minimum-insertion-steps-to-make-a-string-palindrome
Javascript and C++ solutions
javascript-and-c-solutions-by-claytonjwo-fn2c
Synopsis:\n\n Recursive Top-Down solutions: let i and j be the indexes corresponding to the substring of s from i to j inclusive (ie. s[i..j])\n\t Base case: if
claytonjwong
NORMAL
2020-01-06T18:14:59.876698+00:00
2020-01-07T23:11:30.201651+00:00
330
false
**Synopsis:**\n\n* **Recursive Top-Down solutions:** let `i` and `j` be the indexes corresponding to the substring of `s` from `i` to `j` inclusive (ie. `s[i..j]`)\n\t* Base case: if `i >= j` then return `0`\n\t* Recursive cases:\n\t\t* if `s[i] == s[j]` then return the solution for the sub-problem *without* the charac...
5
1
[]
1
minimum-insertion-steps-to-make-a-string-palindrome
1312. Minimum Insertion Steps to Make a String Palindrome
1312-minimum-insertion-steps-to-make-a-s-s6ai
Intuition\n Describe your first thoughts on how to solve this problem. \nTo make a string palindrome, we need to insert characters in such a way that the result
AShukla889012
NORMAL
2023-05-20T06:36:26.968617+00:00
2023-05-20T06:36:26.968660+00:00
333
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo make a string palindrome, we need to insert characters in such a way that the resulting string reads the same backward as well as forward. We can approach this problem using dynamic programming. The intuition is to determine the minimu...
4
0
['String', 'Dynamic Programming', 'Recursion', 'C++']
2
minimum-insertion-steps-to-make-a-string-palindrome
LPS | [ C++ ] | Recursion -> Memo -> Tabulation -> Space Optimization
lps-c-recursion-memo-tabulation-space-op-61wj
Approach\nUsing the variant of Longest Common Subsequence, i,e Longest Pallindromic Subsequence find the length of LPS \n\nLPS as the name determine longest sub
kshzz24
NORMAL
2023-04-22T07:31:49.661751+00:00
2023-04-22T07:31:49.661785+00:00
338
false
# Approach\nUsing the variant of Longest Common Subsequence, i,e Longest Pallindromic Subsequence find the length of LPS \n\nLPS as the name determine longest subsequence in the string which is a pallindrome, so for the answer we just have to add the elements which are not included in the subsequence.\n\nBefore going t...
4
0
['String', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Longest common Subsequence extension....(Python3)
longest-common-subsequence-extensionpyth-g9b4
Intuition\n Describe your first thoughts on how to solve this problem. \nI literally donnot have any idea then i came up with brute force and it didnt worked\n#
Mohan_66
NORMAL
2023-01-27T15:08:04.468172+00:00
2023-01-27T15:08:04.468206+00:00
271
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI literally donnot have any idea then i came up with brute force and it didnt worked\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis is just a longest common subsequence question just reverse the given string an...
4
0
['Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
short and easy to understand
short-and-easy-to-understand-by-sushants-ke5h
lps(a) = longest common subsequence (a,reverse(a))\nmin no. of deletion = len(a) - lps(a)\n\nclass Solution:\n def minInsertions(self, s: str) -> int:\n
sushants007
NORMAL
2022-05-23T11:56:47.952998+00:00
2022-05-23T11:57:20.250779+00:00
405
false
lps(a) = longest common subsequence (a,reverse(a))\nmin no. of deletion = len(a) - lps(a)\n```\nclass Solution:\n def minInsertions(self, s: str) -> int:\n rs= s[::-1]\n n,m = len(s),len(rs)\n t = [[0 for j in range(m+1)]for i in range(n+1)]\n for i in range(1,n+1):\n for j in ...
4
0
['Dynamic Programming', 'Python']
1
minimum-insertion-steps-to-make-a-string-palindrome
Python Simple Recursive DP with Explanation
python-simple-recursive-dp-with-explanat-4cd6
Define dp(s) as the minimum number of steps to make s palindrome.\nWe\'ll get the recursion below:\ndp(s) = 0 if s == s[::-1]\ndp(s) = dp(s[1:-1]) if s[0] == s[
yasufumy
NORMAL
2020-01-05T05:10:19.272003+00:00
2020-03-21T01:37:55.997865+00:00
522
false
Define `dp(s)` as the minimum number of steps to make `s` palindrome.\nWe\'ll get the recursion below:\n`dp(s) = 0 if s == s[::-1]`\n`dp(s) = dp(s[1:-1]) if s[0] == s[-1]`\n`dp(s) = 1 + min(dp(s[1:]), dp(s[:-1])) otherwise`\n\n\n```python\nfrom functools import lru_cache\n\n\nclass Solution:\n def minInsertions(self...
4
0
['Dynamic Programming', 'Recursion', 'Python', 'Python3']
1
minimum-insertion-steps-to-make-a-string-palindrome
[C++] Simple Recursive DP O(N^2)
c-simple-recursive-dp-on2-by-nicmit-oigl
This hard problem, is not that hard if we try to establish the recurrence relation. \nLet\'s say we start comparing the characters of the string, from both the
nicmit
NORMAL
2020-01-05T04:02:40.907035+00:00
2020-01-05T04:08:33.174144+00:00
373
false
This hard problem, is not that hard if we try to establish the recurrence relation. \nLet\'s say we start comparing the characters of the string, from both the ends i.e. `i` as starting index of string as `0` and `j` as ending index of string as `n-1`, where `n` is the length of the string.\nSo, the recurrence relation...
4
0
['Dynamic Programming', 'C']
0
minimum-insertion-steps-to-make-a-string-palindrome
LPS Based Approach 💯🔥| LCS Variation DP 🚀✅
lps-based-approach-lcs-variation-dp-by-s-hcry
IntuitionTo make a string a palindrome, we need to insert characters into the string. The goal is to find the minimum number of insertions required.The key insi
sharmanishchay
NORMAL
2025-02-05T11:19:27.939657+00:00
2025-02-05T11:19:27.939657+00:00
119
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> To make a string a palindrome, we need to insert characters into the string. The goal is to find the minimum number of insertions required. The key insight here is that the more of the string that is already a palindrome, the fewer inserti...
3
0
['Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
EXPLAINED|| BEGINNER FRIENDLY || DP.
explained-beginner-friendly-dp-by-abhish-whw3
Understanding the Code: Minimum Insertions to Make a Palindrome ,But before that ! what is your problem ppl? Why dont you shameless guys upvote my posts , I wri
Abhishekkant135
NORMAL
2024-07-27T17:36:29.728808+00:00
2024-07-27T17:36:29.728831+00:00
47
false
## Understanding the Code: Minimum Insertions to Make a Palindrome ,But before that ! what is your problem ppl? Why dont you shameless guys upvote my posts , I write such long post puttings so much time and you wont wanna give an upvote ;(\n\n### Problem:\nGiven a string, find the minimum number of insertions required ...
3
0
['Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
🔥Java || Dp (tabulation)
java-dp-tabulation-by-neel_diyora-m595
Code\n\nclass Solution {\n public int minInsertions(String s) {\n String s2 = new StringBuilder(s).reverse().toString();\n int n = s.length();\
anjan_diyora
NORMAL
2023-06-29T16:21:30.839877+00:00
2023-06-29T16:21:30.839902+00:00
618
false
# Code\n```\nclass Solution {\n public int minInsertions(String s) {\n String s2 = new StringBuilder(s).reverse().toString();\n int n = s.length();\n int[][] dp = new int[n+1][n+1];\n\n for(int i = 1; i <= n; i++) {\n for(int j = 1; j <= n; j++) {\n if(s.charAt(i...
3
0
['Java']
1
minimum-insertion-steps-to-make-a-string-palindrome
C++ || DP || EASY TO UNDERSTAND
c-dp-easy-to-understand-by-ganeshkumawat-a602
Code\n\nclass Solution {\npublic:\n int solve(int i,int j,string &s,vector<vector<int>> &dp){\n if(i>=j)return 0;\n if(dp[i][j] != -1)return dp
ganeshkumawat8740
NORMAL
2023-05-26T13:04:21.651864+00:00
2023-05-26T13:04:21.651914+00:00
718
false
# Code\n```\nclass Solution {\npublic:\n int solve(int i,int j,string &s,vector<vector<int>> &dp){\n if(i>=j)return 0;\n if(dp[i][j] != -1)return dp[i][j];\n if(s[i]==s[j]){\n return dp[i][j] = solve(i+1,j-1,s,dp);\n }else{\n return dp[i][j] = min({solve(i+1,j,s,dp),...
3
0
['String', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
✅Without knowing LCS
without-knowing-lcs-by-someshrwt-xocw
Intuition\nStarted thougth process from checking palindrome.\n\n# Approach\n- Approached from checking palindrome.\n- Added base condition.\n- Checked if charac
someshrwt
NORMAL
2023-04-25T06:13:27.749288+00:00
2023-04-25T06:13:27.749322+00:00
382
false
# Intuition\nStarted thougth process from checking palindrome.\n\n# Approach\n- Approached from checking palindrome.\n- Added base condition.\n- Checked if character are same or not.\n- If not I just take the minimum of moving from both the ends.\n\nAnalyzed all the possibilities came up with ```recursion``` solution, ...
3
0
['Dynamic Programming', 'C++']
1
minimum-insertion-steps-to-make-a-string-palindrome
Simple solution using recursion+memoization
simple-solution-using-recursionmemoizati-1rhf
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
durgapranathi2002
NORMAL
2023-04-22T16:12:43.825288+00:00
2023-04-22T16:12:43.825319+00:00
155
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
['Recursion', 'Memoization', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Recursion -> Memoization -> DP with explanations using Go
recursion-memoization-dp-with-explanatio-8uko
Intuition\nDivide the problem into sub problems.\nfor a string s with length n, \n- if s[0]==s[n-1], then f(s) = f(s[1:n-1]) \n- else, f(s) = 1+min(f(s[1:n]), f
nacoward
NORMAL
2023-04-22T13:35:21.255709+00:00
2023-04-22T13:44:34.380018+00:00
446
false
# Intuition\nDivide the problem into sub problems.\nfor a string s with length n, \n- if s[0]==s[n-1], then f(s) = f(s[1:n-1]) \n- else, f(s) = 1+min(f(s[1:n]), f(s(:n-1)))\n\nSo we can use recursion to solve this problem\n\n# Approach\nRecursion\n\n# Complexity\n- Time complexity:\nO(2^N) for the worst situation\n\n- ...
3
0
['Dynamic Programming', 'Recursion', 'Memoization', 'Go']
0
minimum-insertion-steps-to-make-a-string-palindrome
🎯TLE -> DP approach (Using Two Pointers)✔
tle-dp-approach-using-two-pointers-by-ha-buz8
Intuition\n Describe your first thoughts on how to solve this problem. \nLet\'s say s="abscsdfa". The longest palindromic subsequence in this string is "ascsa".
harsh6176
NORMAL
2023-04-22T08:54:46.753403+00:00
2023-04-22T08:54:46.753443+00:00
345
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s say s="abscsdfa". The longest palindromic subsequence in this string is "ascsa". So, the number of insertions required is `8 - 5 = 3`.\n\nSo we will first find longest palindromic subsequence and then will subtract from total lengt...
3
0
['Two Pointers', 'String', 'Dynamic Programming', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Rust, DP, short and concise solution ✅🔔🚩
rust-dp-short-and-concise-solution-by-df-q0s9
Intuition\nSimple dynamic programming approach. The subtask is to solve it for substring of length j starting with index i.\ndp[i][j] - the number of insersions
dfomin
NORMAL
2023-04-22T08:05:20.712628+00:00
2023-04-22T13:10:38.952167+00:00
1,040
false
# Intuition\nSimple dynamic programming approach. The subtask is to solve it for substring of length `j` starting with index `i`.\n`dp[i][j]` - the number of insersions to make palindrome from substring `s[i..=i+j]`.\nEvery time you add one more character to substring you check if it\'s the same as first character, if ...
3
0
['Rust']
2
minimum-insertion-steps-to-make-a-string-palindrome
DP || TIME O(m*n),SPACE O(n) || C++
dp-time-omnspace-on-c-by-yash___sharma-d94j
\nclass Solution {\npublic:\n int minInsertions(string s1) {\n int n = s1.length();\n vector<int> dp1(n+1,0),dp2(n+1,0);\n string s2 = s
yash___sharma_
NORMAL
2023-04-22T03:58:26.224477+00:00
2023-04-22T03:58:26.224506+00:00
617
false
````\nclass Solution {\npublic:\n int minInsertions(string s1) {\n int n = s1.length();\n vector<int> dp1(n+1,0),dp2(n+1,0);\n string s2 = s1;\n reverse(s1.begin(),s1.end());\n int i,j;\n for(i = 1; i <= n; i++){\n for(j = 1; j <= n; j++){\n if(s1[i...
3
0
['Dynamic Programming', 'C', 'C++']
1
minimum-insertion-steps-to-make-a-string-palindrome
Python3 clean Solution beats 💯 100% with Proof 🔥
python3-clean-solution-beats-100-with-pr-iinb
Code\n\nclass Solution:\n def minInsertions(self, s: str) -> int:\n if s == s[::-1]: return 0 \n n = len(s)\n dp = [[0] * n for _ in ran
quibler7
NORMAL
2023-04-22T03:27:48.083651+00:00
2023-04-22T03:27:48.083682+00:00
1,872
false
# Code\n```\nclass Solution:\n def minInsertions(self, s: str) -> int:\n if s == s[::-1]: return 0 \n n = len(s)\n dp = [[0] * n for _ in range(n)]\n for i in range(n-1,-1,-1):\n dp[i][i] = 1\n for j in range(i+1,n):\n if s[i] == s[j]:dp[i][j] = dp[i+1...
3
0
['Python3']
1
minimum-insertion-steps-to-make-a-string-palindrome
Java | DP | 10 lines | Clean & simple code
java-dp-10-lines-clean-simple-code-by-ju-txak
Intuition\n Describe your first thoughts on how to solve this problem. \nIf we figure out the longest palindromic subsequence as per this leetcode problem, the
judgementdey
NORMAL
2023-04-22T01:46:45.789465+00:00
2023-04-22T01:50:44.356158+00:00
148
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we figure out the longest palindromic subsequence as per [this leetcode problem](https://leetcode.com/problems/longest-palindromic-subsequence/description/), the answer to the current problem should be the length of the string - the le...
3
0
['String', 'Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
c++ memoization solution (easiest)
c-memoization-solution-easiest-by-h_wan8-2kc3
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
h_WaN8H_
NORMAL
2023-04-22T01:21:11.482816+00:00
2023-04-22T01:21:11.482860+00:00
472
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
['String', 'Recursion', 'Memoization', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
[ C++ ] [ Dynamic Programming ] [ Longest Palindromic Subsequence ] [ Longest Common Subsequence ]
c-dynamic-programming-longest-palindromi-lyea
Code\n\nclass Solution {\npublic:\n int lcs(string s,string b){\n int a=s.size();\n int m=b.size();\n int dp[a+1][m+1];\n for(int i=0;i<a+1;i++){
Sosuke23
NORMAL
2023-04-22T00:58:12.256731+00:00
2023-04-22T00:58:12.256757+00:00
165
false
# Code\n```\nclass Solution {\npublic:\n int lcs(string s,string b){\n int a=s.size();\n int m=b.size();\n int dp[a+1][m+1];\n for(int i=0;i<a+1;i++){\n for(int j=0;j<m+1;j++){\n if(i==0 || j==0)\n dp[i][j]=0;\n }\n }\n for(int i=1;i<a+1;i++){\n for(int j=...
3
0
['Dynamic Programming', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
LONGEST PLINDROMIC SUBSEQUENCE || C++
longest-plindromic-subsequence-c-by-yash-47ls
\nclass Solution {\npublic:\n int minInsertions(string s1) {\n int n = s1.length();\n vector<int> dp1(n+1,0),dp2(n+1,0);\n string s2 = s
yash___sharma_
NORMAL
2023-04-20T06:02:23.184060+00:00
2023-04-20T06:02:23.184104+00:00
884
false
````\nclass Solution {\npublic:\n int minInsertions(string s1) {\n int n = s1.length();\n vector<int> dp1(n+1,0),dp2(n+1,0);\n string s2 = s1;\n reverse(s1.begin(),s1.end());\n int i,j;\n for(i = 1; i <= n; i++){\n for(j = 1; j <= n; j++){\n if(s1[i...
3
0
['Dynamic Programming', 'C', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Easy Java Solution| Using Recursion & Dynamic Programming
easy-java-solution-using-recursion-dynam-v1hh
Code\n\nclass Solution {\n public int minInsertions(String s) {\n int n= s.length();\n int[][] dp= new int[n+1][n+1];\n for(int[] temp:
PiyushParmar_28
NORMAL
2023-02-05T11:54:44.056915+00:00
2023-02-05T11:54:44.056958+00:00
449
false
# Code\n```\nclass Solution {\n public int minInsertions(String s) {\n int n= s.length();\n int[][] dp= new int[n+1][n+1];\n for(int[] temp: dp){\n Arrays.fill(temp, -1);\n }\n return getCount(s, 0, n-1, dp);\n }\n\n public int getCount(String s, int left, int righ...
3
0
['String', 'Dynamic Programming', 'Recursion', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
JAVA | SIMPLE EXPLANATION | CODE WITH DETAILED COMMENTS
java-simple-explanation-code-with-detail-wom9
Simple Explanation of Bottom-up (Tabulation) approach\n\nhttps://www.youtube.com/watch?v=7UpPnWW9GJY\n\nFor more:-\nTelegram group - https://t.me/+IK5-RpKtVWUxM
prateekool109
NORMAL
2022-08-04T06:11:46.227047+00:00
2022-08-06T05:16:03.694285+00:00
649
false
Simple Explanation of Bottom-up (Tabulation) approach\n\nhttps://www.youtube.com/watch?v=7UpPnWW9GJY\n\nFor more:-\n**Telegram group** - https://t.me/+IK5-RpKtVWUxMDI1\n**Telegram channel**- https://t.me/betterSoftEng\n\n```\nclass LongestPalindromeInAStringSolution{\n static String longestPalin(String S){\n ...
3
0
['Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
JAVA | SIMPLE EXPLANATION | CODE WITH DETAILED COMMENTS
java-simple-explanation-code-with-detail-4n6e
Simple explanation https://www.youtube.com/watch?v=IWV3wolx13k\n\nAbove video explains Recursion and Top-Down DP approach. Part 2 of the video will have Bottom
prateekool109
NORMAL
2022-08-01T13:37:02.437506+00:00
2022-08-06T05:16:16.254036+00:00
353
false
Simple explanation https://www.youtube.com/watch?v=IWV3wolx13k\n\nAbove video explains Recursion and Top-Down DP approach. Part 2 of the video will have Bottom up approach as well\n\nFor more:-\n**Telegram group** - https://t.me/+IK5-RpKtVWUxMDI1\n**Telegram channel** - https://t.me/betterSoftEng\n\n```\nclass FormAPal...
3
0
['Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
✅ [C++, Java, Python] Easy to understand | O(n^2) time and O(n) space | bottom up DP
c-java-python-easy-to-understand-on2-tim-b2it
Minimum Insertion Steps to Make a String Palindrome = Length of string - Length of longest palindromic subsequence. \n\nC++ implementation:\n\nclass Solution {
damian_arado
NORMAL
2022-07-03T14:51:11.915000+00:00
2022-07-03T14:52:30.138227+00:00
376
false
Minimum Insertion Steps to Make a String Palindrome = Length of string - Length of longest palindromic subsequence. \n\nC++ implementation:\n```\nclass Solution {\nprivate:\n int findLCS(string &s1, string &s2) {\n int n = s1.size();\n vector<int> dp(n + 1, 0);\n for(int i = 1; i <= n; ++i) {\n...
3
0
['Dynamic Programming', 'C', 'Python', 'C++', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Java brute force using DP. IF anyone knows a better solution please share
java-brute-force-using-dp-if-anyone-know-fvzt
\nclass Solution {\n public int minInsertions(String s) {\n int len = s.length();\n StringBuilder sb = new StringBuilder();\n sb.append(
CosmicLeo
NORMAL
2022-01-21T14:13:56.171103+00:00
2022-01-21T14:13:56.171144+00:00
227
false
```\nclass Solution {\n public int minInsertions(String s) {\n int len = s.length();\n StringBuilder sb = new StringBuilder();\n sb.append(s);\n sb.reverse();\n int [][] dp = new int[len+1][len+1];\n \n for(int i =0;i<len+1;i++){\n dp[i][0]=0;\n }\n ...
3
0
['Dynamic Programming', 'Java']
1
minimum-insertion-steps-to-make-a-string-palindrome
Why won't the frequency of letters work. Why will LCS work.
why-wont-the-frequency-of-letters-work-w-y3ug
\ndef minInsertions(self, s: str) -> int:\n if s == s[::-1] or len(s)==1:\n return 0\n t = s[::-1]\n dp = [[0]*(len(s)+1) for _
rahulranjan95
NORMAL
2021-09-15T04:58:12.918313+00:00
2021-09-15T04:58:12.918363+00:00
332
false
```\ndef minInsertions(self, s: str) -> int:\n if s == s[::-1] or len(s)==1:\n return 0\n t = s[::-1]\n dp = [[0]*(len(s)+1) for _ in range(len(t)+1)]\n for i in range(1,len(s)+1):\n for j in range(1,len(t)+1):\n if s[i-1]==t[j-1]:\n dp...
3
0
['Dynamic Programming', 'Python', 'Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
[C++] - Top-down and Bottom-up approaches
c-top-down-and-bottom-up-approaches-by-m-e9cc
Top Down Approach:\n\nclass Solution {\npublic:\n int solve(string &str,int low,int high,vector<vector<int> > &dp){\n if(low>high)\n return
morning_coder
NORMAL
2021-02-23T16:27:13.257843+00:00
2021-02-23T16:27:13.257880+00:00
184
false
**Top Down Approach:**\n```\nclass Solution {\npublic:\n int solve(string &str,int low,int high,vector<vector<int> > &dp){\n if(low>high)\n return 0;\n if(dp[low][high]!=-1)\n return dp[low][high];\n if(low==high){\n return dp[low][high]=0;\n }\n if...
3
2
['Dynamic Programming', 'Memoization', 'C', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
[C++] [DP] Heavy Comments on Each Line
c-dp-heavy-comments-on-each-line-by-raja-te72
\nclass Solution {\npublic:\n // Before reading this, I would highly recommend to take a rought notebook and draw the flow chart of these recursive calls, ch
rajatsing
NORMAL
2020-12-24T18:35:29.893280+00:00
2020-12-24T18:36:03.400970+00:00
470
false
```\nclass Solution {\npublic:\n // Before reading this, I would highly recommend to take a rought notebook and draw the flow chart of these recursive calls, change the variables values and check for yourself on how all these recursive values are adding up finally and what value is actually getting returned.\n// It ...
3
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C']
1
minimum-insertion-steps-to-make-a-string-palindrome
JAVA | Easy Solution Using Longest Common SubSequence
java-easy-solution-using-longest-common-kn0js
```\nclass Solution {\n public int minInsertions(String s) {\n StringBuilder S = new StringBuilder();\n S.append(s);\n return S.length()
onefineday01
NORMAL
2020-05-10T05:50:19.684541+00:00
2020-05-10T05:50:19.684576+00:00
586
false
```\nclass Solution {\n public int minInsertions(String s) {\n StringBuilder S = new StringBuilder();\n S.append(s);\n return S.length() - longestCommonSubsequence(s, S.reverse().toString());\n }\n public int longestCommonSubsequence(String text1, String text2) {\n int m = text1.len...
3
0
['Dynamic Programming', 'Java']
1
minimum-insertion-steps-to-make-a-string-palindrome
Java DFS with memoization similar to 1216. Valid Palindrome III
java-dfs-with-memoization-similar-to-121-b7u5
java\nclass Solution {\n public int minInsertions(String s) {\n if (s == null || s.length() == 0) return 0;\n int[][] min = new int[s.length()]
dreamyjpl
NORMAL
2020-01-05T04:01:45.572659+00:00
2020-01-07T03:29:23.286663+00:00
713
false
```java\nclass Solution {\n public int minInsertions(String s) {\n if (s == null || s.length() == 0) return 0;\n int[][] min = new int[s.length()][s.length()];\n for (int[] row : min) Arrays.fill(row, -1);\n return dp(s, 0, s.length() - 1, min);\n }\n private int dp(String s, int l,...
3
1
['Depth-First Search', 'Memoization', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
[Java] Small code with Recursion with Memoization
java-small-code-with-recursion-with-memo-q30m
```\n int[][]dp;\n public int minInsertions(String s) {\n int n = s.length();\n dp = new int[n][n];\n for(int i=0; i=j) return 0;\n
tans12
NORMAL
2020-01-05T04:01:34.038145+00:00
2020-01-05T04:01:34.038187+00:00
324
false
```\n int[][]dp;\n public int minInsertions(String s) {\n int n = s.length();\n dp = new int[n][n];\n for(int i=0; i<n; i++) {\n Arrays.fill(dp[i], Integer.MAX_VALUE);\n }\n int res = find(s.toCharArray(), 0, s.length()-1);\n return res;\n }\n \n int find...
3
1
[]
0
minimum-insertion-steps-to-make-a-string-palindrome
Easy to understand cpp solution with space optimization(beats 99.68%)
easy-to-understand-cpp-solution-with-spa-zg67
Intuition and Approach The basic idea is to run Longest palindrome sequence on the string and then subtract the value from the string length to find out which a
Srikrishna_Kidambi
NORMAL
2025-04-06T17:46:16.287329+00:00
2025-04-06T17:46:16.287329+00:00
45
false
# Intuition and Approach <!-- Describe your first thoughts on how to solve this problem. --> - The basic idea is to run Longest palindrome sequence on the string and then subtract the value from the string length to find out which are need to duplicated and put in right place to make the string palindrome. - The longes...
2
0
['Dynamic Programming', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Java Solution [Beats 97.84%] | LCS Variation | LPS | Minimum Deletions
java-solution-beats-9784-lcs-variation-l-02wt
ApproachFinding the number of characters need to be deleted and then adding those characters on the opposite side of the string to get total number of insertion
neel-thakker
NORMAL
2025-02-02T18:39:45.291885+00:00
2025-02-02T18:39:45.291885+00:00
75
false
# Approach <!-- Describe your approach to solving the problem. --> Finding the number of characters need to be deleted and then adding those characters on the opposite side of the string to get total number of insertions (minimum) For minimum # of deletions: find LCS of s with reversed self # Code ```java [] class ...
2
0
['Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
dp || string c++
dp-string-c-by-gaurav_bahukhandi-kj6d
IntuitionApproachSAME AS MINIMUM DELECTION REQUIRED TO MAKE STRING PALINDROME .FIRST CALCULATE THE LONGEST COMMAN SUBSEQUENCE OF THE STRING OF ORIGINAL AND REVE
Gaurav_bahukhandi
NORMAL
2025-01-29T13:32:34.839043+00:00
2025-01-29T13:32:34.839043+00:00
131
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> SAME AS MINIMUM DELECTION REQUIRED TO MAKE STRING PALINDROME .FIRST CALCULATE THE LONGEST COMMAN SUBSEQUENCE OF THE STRING OF ORIGINAL AND REVERSED STRING BY CALCULATING LC...
2
0
['String', 'Dynamic Programming', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
"Palindrome Perfection: Efficient Dynamic Programming for Minimum Insertions" || Same as 516. LPS✔️
palindrome-perfection-efficient-dynamic-0vzah
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires finding the minimum number of insertions needed to make a given st
manveet22280
NORMAL
2024-07-18T17:21:21.592328+00:00
2024-07-18T17:21:21.592354+00:00
664
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires finding the minimum number of insertions needed to make a given string a palindrome. This can be approached by leveraging the concept of the Longest Common Subsequence (LCS).\n# Approach\n<!-- Describe your approach t...
2
0
['String', 'Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Easy || Beginner's Friendly || Easy to Understand || ✅✅
easy-beginners-friendly-easy-to-understa-q5wi
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
AadiVerma07
NORMAL
2024-03-28T00:15:01.810442+00:00
2024-03-28T00:15:01.810465+00:00
13
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Easy to Understand Java Code || Aditya Verma Approach || LPS
easy-to-understand-java-code-aditya-verm-ipw5
Complexity\n- Time complexity:\nO(mn)\n- Space complexity:\nO(mn)\n# Code\n\nclass Solution {\n public int minInsertions(String s) {\n StringBuilder s
Saurabh_Mishra06
NORMAL
2024-02-20T05:06:14.986822+00:00
2024-02-20T05:06:14.986847+00:00
101
false
# Complexity\n- Time complexity:\nO(m*n)\n- Space complexity:\nO(m*n)\n# Code\n```\nclass Solution {\n public int minInsertions(String s) {\n StringBuilder s2 = new StringBuilder(s);\n s2.reverse();\n \n int m = s.length();\n int n = s2.length();\n\n int[][] t = new int[m+1][n+1];\...
2
0
['Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Minimum Insertion Steps to Make a String Palindrome | 90% Faster | Simplest Approach | DP
minimum-insertion-steps-to-make-a-string-yfcj
Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to find the minimum insertions required to make a string palindrome. Let us kee
Utkarsh_mishra0801
NORMAL
2024-02-12T13:02:00.067428+00:00
2024-02-12T13:02:00.067462+00:00
51
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to find the minimum insertions required to make a string palindrome. Let us keep the \u201Cminimum\u201D criteria aside and think, how can we make any given string palindrome by inserting characters?\n\nThe easiest way is to add t...
2
0
['Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
Using dynamic Programing(Tabulation).
using-dynamic-programingtabulation-by-sh-98ta
Intuition\n Describe your first thoughts on how to solve this problem. \nIf we find the longest length of the character which are palindrome then we have to do
Shrishti007
NORMAL
2024-02-12T09:13:15.574894+00:00
2024-02-12T09:13:15.574932+00:00
41
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we find the longest length of the character which are palindrome then we have to do only insertion for those who are not palindrome.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMin insertions equal the diffe...
2
0
['Python3']
1
minimum-insertion-steps-to-make-a-string-palindrome
C++, DP, tabulation, space optimized, simple
c-dp-tabulation-space-optimized-simple-b-jrzc
Intuition\n\n\n* Check longest common subsequence between string s and it\'s reverse string t.\n* len(s) - lcs(s, t) will be the number of non-matching characte
Arif-Kalluru
NORMAL
2023-07-19T07:46:36.719481+00:00
2023-07-19T07:46:36.719506+00:00
284
false
# Intuition\n\n```\n* Check longest common subsequence between string s and it\'s reverse string t.\n* len(s) - lcs(s, t) will be the number of non-matching characters.\n* Hence we need to add those many characters.\n```\n\n# Tabulation (Not space optimized)\n```\nclass Solution {\npublic:\n int minInsertions(string...
2
0
['String', 'Dynamic Programming', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
c++ memoization approach without using LCS
c-memoization-approach-without-using-lcs-sn2k
Solution without using reverse of the string\n\nclass Solution {\npublic:\n\n int helper(string &s, int i, int j, vector<vector<int>> & dp){\n if(i>
ankitkr23
NORMAL
2023-05-22T08:05:35.447198+00:00
2023-05-22T08:05:35.447247+00:00
14
false
Solution without using reverse of the string\n```\nclass Solution {\npublic:\n\n int helper(string &s, int i, int j, vector<vector<int>> & dp){\n if(i>j)return 0;\n if(i==j)return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n if(s[i-1]==s[j-1]){\n return dp[i][j]=helper(s, i+1,...
2
0
['C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Ex-Amazon explains a solution with a video, Python, JavaScript, Java and C++
ex-amazon-explains-a-solution-with-a-vid-t9n3
My youtube channel - KeetCode(Ex-Amazon)\nI create 155 videos for leetcode questions as of April 24, 2023. I believe my channel helps you prepare for the coming
niits
NORMAL
2023-04-23T21:48:34.796482+00:00
2023-04-24T02:59:12.117096+00:00
721
false
# My youtube channel - KeetCode(Ex-Amazon)\nI create 155 videos for leetcode questions as of April 24, 2023. I believe my channel helps you prepare for the coming technical interviews. Please subscribe my channel!\n\n### Please subscribe my channel - KeetCode(Ex-Amazon) from here.\n\n**I created a video for this questi...
2
0
['C++', 'Java', 'Python3', 'JavaScript']
0
minimum-insertion-steps-to-make-a-string-palindrome
JAVA | DP | Well Explained🔥
java-dp-well-explained-by-pavittarkumara-kb38
Intuition\n Describe your first thoughts on how to solve this problem. \nMy first intuition was that the no. of insertions needed to make the string palindromic
pavittarkumarazad1
NORMAL
2023-04-23T08:22:31.628259+00:00
2023-04-23T08:23:04.759936+00:00
103
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy first intuition was that the no. of insertions needed to make the string palindromic would be **same as the no. of deletions** required to make the string palindromic. suppose we have the string ***abbca***. \n\nEither we can add c to ...
2
0
['Dynamic Programming', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
[ Python ] ✅✅ Simple Python Solution Using Dynamic Programming🥳✌👍
python-simple-python-solution-using-dyna-r0yf
If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 1317 ms, faster than 27.39% of Python3 online submissi
ashok_kumar_meghvanshi
NORMAL
2023-04-22T16:44:07.756828+00:00
2023-04-22T16:44:07.756861+00:00
1,008
false
# If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 1317 ms, faster than 27.39% of Python3 online submissions for Minimum Insertion Steps to Make a String Palindrome.\n# Memory Usage: 16 MB, less than 67.55% of Python3 online submissions for Minimum Insertion Step...
2
0
['Dynamic Programming', 'Memoization', 'Python', 'Python3']
1
minimum-insertion-steps-to-make-a-string-palindrome
✅✅ BEST C++ solution DP ( 2 approach ) Memorization vs Tabulation 💯💯 ⬆⬆⬆⬆
best-c-solution-dp-2-approach-memorizati-0lr3
\n\n# Code\n\n#define vi vector<int>\n#define vvi vector<vi>\n\nclass Solution {\npublic:\n int solveMem(string& a, string& b, int i, int j, vvi& dp) {\n
Sandipan58
NORMAL
2023-04-22T14:33:10.105714+00:00
2023-04-22T14:33:10.105739+00:00
22
false
\n\n# Code\n```\n#define vi vector<int>\n#define vvi vector<vi>\n\nclass Solution {\npublic:\n int solveMem(string& a, string& b, int i, int j, vvi& dp) {\n if(i == a.length() || j == b.length()) return 0;\n if(dp[i][j] != -1) return dp[i][j];\n if(a[i] == b[j]) dp[i][j] = 1 + solveMem(a,...
2
0
['C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Very Easy DP Solution | C++ & Java | Fast & Explained
very-easy-dp-solution-c-java-fast-explai-yh10
Solution\n- Use Dynamic Programming technique to try all possible ways to make the string palindrome.\n- The dp array is a 2D array, where dp[l][r] is the minim
Zeyad_Nasef
NORMAL
2023-04-22T13:19:51.638434+00:00
2023-04-22T13:19:51.638466+00:00
79
false
# Solution\n- Use `Dynamic Programming` technique to try all possible ways to make the string palindrome.\n- The `dp` array is a 2D array, where `dp[l][r]` is the minimum number of insertions needed to make the substring `s[l..r]` a palindrome.\n- If `s[l] == s[r]`, then you can move the 2 pointers to the inside and ca...
2
0
['C', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Solution using dp
solution-using-dp-by-priyanshu11-l1ad
Intuition\nTo solve this problem, we can use dynamic programming (DP). We define dp[i][j] as the minimum number of insertions needed to make the substring s[i..
priyanshu11_
NORMAL
2023-04-22T13:18:22.958226+00:00
2023-04-22T13:18:22.958276+00:00
51
false
# Intuition\nTo solve this problem, we can use dynamic programming (DP). We define dp[i][j] as the minimum number of insertions needed to make the substring s[i...j] a palindrome.\n\n# Approach\nWe can observe that if the characters s[i] and s[j] are the same, then we don\'t need to do anything and we can just consider...
2
0
['String', 'Dynamic Programming', 'C++', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
python 3 - top down dp
python-3-top-down-dp-by-markwongwkh-l70q
Intuition\nLogic is straightforward.\n\nstate variable = left, right\nDo all combination of left and right -> DP should be used.\nIf s[left] == s[right], skip b
markwongwkh
NORMAL
2023-04-22T08:30:15.652773+00:00
2023-04-22T08:30:15.652817+00:00
308
false
# Intuition\nLogic is straightforward.\n\nstate variable = left, right\nDo all combination of left and right -> DP should be used.\nIf s[left] == s[right], skip both left and right. Else, add either s[left] or s[right] and repeat the process.\n\n# Approach\ntop-down dp\n\n# Complexity\n- Time complexity:\nO(n^2) -> dp ...
2
0
['Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
⭐✅Clean, Simple & Easy C++ Code💯 || Memoization✅
clean-simple-easy-c-code-memoization-by-anrgv
Code\n## Please Upvote if u liked my Solution\uD83E\uDD17\n\nclass Solution {\npublic:\n int helper(int i,int j,string& s,vector<vector<int>>& dp){\n
aDish_21
NORMAL
2023-04-22T08:17:05.158152+00:00
2023-04-22T08:25:04.523389+00:00
190
false
# Code\n## Please Upvote if u liked my Solution\uD83E\uDD17\n```\nclass Solution {\npublic:\n int helper(int i,int j,string& s,vector<vector<int>>& dp){\n if(i >= j)\n return 0;\n if(dp[i][j] != -1)\n return dp[i][j];\n int left = INT_MAX,right = INT_MAX;\n if(s[i] =...
2
0
['String', 'Dynamic Programming', 'Memoization', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Typescript top-down dynamic programming detailed solution. Beats 100%
typescript-top-down-dynamic-programming-rj2qr
Intuition\n Describe your first thoughts on how to solve this problem. \nA Palindrome string is one that reads the same forward and backward. One way to determi
Adetomiwa
NORMAL
2023-04-22T06:56:20.616707+00:00
2023-04-22T13:39:51.857017+00:00
407
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA Palindrome string is one that reads the same forward and backward. One way to determine if a string is palindromic is by using a **two-pointer algorithm**. In this case, we use two pointers, one at the start of the string and the other ...
2
0
['Two Pointers', 'Dynamic Programming', 'TypeScript']
0
minimum-insertion-steps-to-make-a-string-palindrome
✅ Java | Top Down DP - Memoization Approach
java-top-down-dp-memoization-approach-by-uij2
\n// Approach 2: Top Down DP (Memoization)\n\n// Time complexity: O(n^2)\n// Space complexity: O(n^2)\n\nclass Solution {\n int[][] memo;\n \n public i
prashantkachare
NORMAL
2023-04-22T06:28:45.237226+00:00
2023-04-22T06:28:45.237268+00:00
208
false
```\n// Approach 2: Top Down DP (Memoization)\n\n// Time complexity: O(n^2)\n// Space complexity: O(n^2)\n\nclass Solution {\n int[][] memo;\n \n public int minInsertions(String s) {\n int n = s.length();\n memo = new int[n][n];\n return lcs(s, 0, n - 1); \n }\n \n private int ...
2
0
['Dynamic Programming', 'Memoization', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Python easy 7-liner | DP | Top-down & Bottom-up
python-easy-7-liner-dp-top-down-bottom-u-jaf7
Code\n\nTop Down\n\nclass Solution:\n def minInsertions(self, s: str) -> int:\n @lru_cache(None)\n def dp(i, j):\n if i >= j:\n
atulkoshta
NORMAL
2023-04-22T05:03:33.568511+00:00
2023-04-22T05:35:57.058148+00:00
183
false
# Code\n\n***Top Down***\n```\nclass Solution:\n def minInsertions(self, s: str) -> int:\n @lru_cache(None)\n def dp(i, j):\n if i >= j:\n return 0\n\n if s[i] == s[j]:\n return dp(i+1, j-1)\n else:\n return 1+min(dp(i+1, j),...
2
0
['Dynamic Programming', 'Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
✅ Java | Naive Recursion - Brute Force Approach
java-naive-recursion-brute-force-approac-729t
\n// Approach 1: Naive Recursion (Brute Force Approach) - TLE\n\n// Time complexity: O(2^n)\n// Space complexity: O(2^n)\n\nclass Solution {\n public int min
prashantkachare
NORMAL
2023-04-22T04:53:17.093938+00:00
2023-04-22T04:53:17.093999+00:00
63
false
```\n// Approach 1: Naive Recursion (Brute Force Approach) - TLE\n\n// Time complexity: O(2^n)\n// Space complexity: O(2^n)\n\nclass Solution {\n public int minInsertions(String s) {\n return lcs(s, 0, s.length() - 1); \n }\n \n private int lcs(String s, int left, int right) {\n if (left > ...
2
0
['Recursion', 'Java']
0
minimum-insertion-steps-to-make-a-string-palindrome
Python. 2 solutions. Recursive 1-liner DP. Iterative space optimised DP.
python-2-solutions-recursive-1-liner-dp-7lcqk
Approach 1: Recursive DP with memoization\n\n# Complexity\n- Time complexity: O(n^2)\n\n- Space complexity: O(n^2)\n\nwhere, n is length of s.\n\n# Code\nFormat
darshan-as
NORMAL
2023-04-22T04:51:31.643903+00:00
2023-04-22T04:51:31.643945+00:00
93
false
# Approach 1: Recursive DP with memoization\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n\n- Space complexity: $$O(n^2)$$\n\nwhere, `n is length of s`.\n\n# Code\nFormatted to multiline for readability.\n```python\nclass Solution:\n def minInsertions(self, s: str) -> int:\n @cache\n def min_inserts(...
2
1
['String', 'Dynamic Programming', 'Recursion', 'Python', 'Python3']
0
minimum-insertion-steps-to-make-a-string-palindrome
📌📌 C++ || DP || Memo || Faster || Easy To Understand 🤷‍♂️🤷‍♂️
c-dp-memo-faster-easy-to-understand-by-_-e4ly
Memo\n\n Time Complexity :- O(N * N)\n\n Space Complexity :- O(N * N)\n\n\nclass Solution {\npublic:\n \n // declare a 2D dp array\n \n vector<vecto
__KR_SHANU_IITG
NORMAL
2023-04-22T03:56:22.656076+00:00
2023-04-22T03:56:22.656117+00:00
120
false
* ***Memo***\n\n* ***Time Complexity :- O(N * N)***\n\n* ***Space Complexity :- O(N * N)***\n\n```\nclass Solution {\npublic:\n \n // declare a 2D dp array\n \n vector<vector<int>> dp;\n \n int helper(string &str, int low, int high)\n {\n // base case\n \n if(low >= high)\n ...
2
0
['Dynamic Programming', 'Memoization', 'C', 'C++']
0
minimum-insertion-steps-to-make-a-string-palindrome
Easy Explaination 🔥🔥 || Minimum Insertion Steps to make string palimdrome
easy-explaination-minimum-insertion-step-0mnc
\tclass Solution {\n\tpublic:\n\t\tint vec[501][501];\n\n\t\tint fun(string &s1, string &s2, int n1, int n2)\n\t\t{\n\t\t\tif(n1 == 0 || n2 == 0)\n\t\t\t\tretur
ritiktrippathi
NORMAL
2023-04-22T03:46:52.913350+00:00
2023-04-22T03:46:52.913382+00:00
15
false
\tclass Solution {\n\tpublic:\n\t\tint vec[501][501];\n\n\t\tint fun(string &s1, string &s2, int n1, int n2)\n\t\t{\n\t\t\tif(n1 == 0 || n2 == 0)\n\t\t\t\treturn 0;\n\n\t\t\tif(vec[n1 - 1][n2 - 1] != -1)\n\t\t\t\treturn vec[n1 - 1][n2 - 1];\n\n\t\t\tif(s1[n1 - 1] == s2[n2 - 1])\n\t\t\t\treturn vec[n1 - 1][n2 - 1] = (1 ...
2
0
['String', 'Dynamic Programming', 'Memoization']
0
minimum-insertion-steps-to-make-a-string-palindrome
Easy Golang Solution
easy-golang-solution-by-shellpy03-zaae
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
shellpy03
NORMAL
2023-04-22T02:31:35.662627+00:00
2023-04-22T02:31:35.662657+00:00
42
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) because of (n+1)*(n+1) array.\n\n- Space complexity:\no(n^2) because of (n+1)*(n+1) array.\n\n\n# Code\n```\npackage main\n\...
2
0
['Brainteaser', 'Go']
0
minimum-insertion-steps-to-make-a-string-palindrome
C# Using Longest Palindromic Subsequence
c-using-longest-palindromic-subsequence-3jdhy
Approach\nUsing 516. Longest Palindromic Subsequence.\nIf we know the longest palindromic sub-sequence is x and the length of the string is n then, what is the
dmitriy-maksimov
NORMAL
2023-04-22T00:43:22.083893+00:00
2023-04-22T00:43:22.083920+00:00
417
false
# Approach\nUsing [516. Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/).\nIf we know the longest palindromic sub-sequence is x and the length of the string is $$n$$ then, what is the answer to this problem? It is $$n - x$$ as we need $$n - x$$ insertions to make the rema...
2
0
['C#']
0
last-stone-weight
[Java/C++/Python] Priority Queue
javacpython-priority-queue-by-lee215-p4p3
Explanation\nPut all elements into a priority queue.\nPop out the two biggest, push back the difference,\nuntil there are no more two elements left.\n\n\n# Comp
lee215
NORMAL
2019-05-19T04:21:18.876547+00:00
2020-01-08T15:50:09.007111+00:00
59,197
false
# **Explanation**\nPut all elements into a priority queue.\nPop out the two biggest, push back the difference,\nuntil there are no more two elements left.\n<br>\n\n# **Complexity**\nTime `O(NlogN)`\nSpace `O(N)`\n<br>\n\n**Java, PriorityQueue**\n```java\n public int lastStoneWeight(int[] A) {\n PriorityQueue<...
364
3
[]
65
last-stone-weight
✅ Simple easy c++ solution
simple-easy-c-solution-by-naman_rathod-eyi1
\n\n\n int lastStoneWeight(vector<int>& stones) \n {\n priority_queue<int> pq(stones.begin(),stones.end());\n while(pq.size()>1)\n {\n
Naman_Rathod
NORMAL
2022-04-07T00:42:44.754643+00:00
2022-04-07T00:42:44.754677+00:00
18,203
false
![image](https://assets.leetcode.com/users/images/fc5f29d9-7e2e-4f5b-a3d9-2c5654652b76_1649292145.9654834.png)\n\n```\n int lastStoneWeight(vector<int>& stones) \n {\n priority_queue<int> pq(stones.begin(),stones.end());\n while(pq.size()>1)\n {\n int y=pq.top();\n pq.pop()...
193
0
[]
25
last-stone-weight
[Python] Beginner-friendly Optimisation Process with Explanation
python-beginner-friendly-optimisation-pr-27cq
Introduction\n\nGiven an array of stones stones, we repeatedly "smash" (i.e., compare) the two heaviest stones together until there is at most one stone left. I
zayne-siew
NORMAL
2022-04-07T01:57:02.104507+00:00
2022-04-07T01:57:02.104551+00:00
18,567
false
### Introduction\n\nGiven an array of stones `stones`, we repeatedly "smash" (i.e., compare) the two heaviest stones together until there is at most one stone left. If the two heaviest stones are of the same weight, both stones are "destroyed" (i.e., both weights become 0), otherwise, a stone with the absolute weight d...
166
3
['Heap (Priority Queue)', 'Python', 'Python3']
14
last-stone-weight
C++ Explained 🔥 Easy Solution 🔥Priority Queue 🔥
c-explained-easy-solution-priority-queue-3953
PLEASE UPVOTE \uD83D\uDC4D\n# Intuition\n- #### To solve this problem, we can use a priority queue to keep track of the heaviest stones. \n- #### At each turn,
ribhav_32
NORMAL
2023-04-24T02:08:23.569056+00:00
2023-04-24T02:08:23.569092+00:00
12,973
false
# **PLEASE UPVOTE \uD83D\uDC4D**\n# Intuition\n- #### To solve this problem, we can use a priority queue to keep track of the heaviest stones. \n- #### At each turn, we can pop the two heaviest stones from the heap, smash them together according to the given rules, and then push the resulting stone (if any) back onto t...
117
2
['Array', 'Queue', 'Heap (Priority Queue)', 'C++']
3
last-stone-weight
Java simple to complex solutions explained -- 0 ms top 100% time 100% memory 2 lines of code only!
java-simple-to-complex-solutions-explain-fcd7
At every step of the algorithm, we need to know the top heaviest stone.\nThe most efficient way to retrieve the max for large input sizes is to use a max heap,
tiagodsilva
NORMAL
2020-04-12T10:57:33.478815+00:00
2020-04-14T08:19:18.648027+00:00
9,972
false
At every step of the algorithm, we need to know the top heaviest stone.\nThe most efficient way to retrieve the max for large input sizes is to use a max heap, which in Java is a PriorityQueue (min heap) with a reverse comparator:\n\nO(n log (n)) time O(n) space \n1 ms time 37.5 MB space\n91% time 100% space\n\n```\n ...
103
0
[]
13
last-stone-weight
A solid EXPLANATION
a-solid-explanation-by-hi-malik-002g
How\'s going Ladies - n - Gentlemen, today we are going to solve another coolest problem i.e. Last Stone Weight \n\nOkay, so first of all let\'s understand the
hi-malik
NORMAL
2022-04-07T02:03:53.258617+00:00
2022-04-07T07:37:18.185859+00:00
4,521
false
How\'s going Ladies - n - Gentlemen, today we are going to solve another coolest problem i.e. **Last Stone Weight** \n\nOkay, so first of all let\'s understand the problem\n\n**We have 2 stones x & y**\n\n![image](https://assets.leetcode.com/users/images/e062b588-f311-49ea-9aa0-c19e720eb38a_1649295151.330421.png)\n\nAn...
90
4
[]
19
last-stone-weight
[Java/Python 3] easy code using PriorityQueue/heapq w/ brief explanation and analysis.
javapython-3-easy-code-using-priorityque-b46h
Sort stones descendingly in PriorityQueue, then pop out pair by pair, compute the difference between them and add back to PriorityQueue.\n\nNote: since we alrea
rock
NORMAL
2019-05-19T04:35:25.806338+00:00
2022-04-07T16:31:42.578315+00:00
7,409
false
Sort stones descendingly in PriorityQueue, then pop out pair by pair, compute the difference between them and add back to PriorityQueue.\n\nNote: since we already know the first poped out is not smaller, it is not necessary to use Math.abs().\n\n```java\n public int lastStoneWeight(int[] stones) {\n // PriorityQ...
48
2
['Heap (Priority Queue)']
8
last-stone-weight
C++ Multiset and Priority Queue
c-multiset-and-priority-queue-by-votruba-ektu
Approach 1: Multiset\n\nint lastStoneWeight(vector<int>& st) {\n multiset<int> s(begin(st), end(st));\n while (s.size() > 1) {\n auto w1 = *prev(s.end());\
votrubac
NORMAL
2019-05-19T04:12:26.519812+00:00
2019-11-10T18:29:28.829732+00:00
6,376
false
#### Approach 1: Multiset\n```\nint lastStoneWeight(vector<int>& st) {\n multiset<int> s(begin(st), end(st));\n while (s.size() > 1) {\n auto w1 = *prev(s.end());\n s.erase(prev(s.end()));\n auto w2 = *prev(s.end());\n s.erase(prev(s.end()));\n if (w1 - w2 > 0) s.insert(w1 - w2);\n }\n return s.empty...
44
3
[]
8
last-stone-weight
Super Simple O(N) Java Solution using bucket sort and two pointers
super-simple-on-java-solution-using-buck-7dzo
```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n int[] buckets = new int[1001];\n for (int i = 0; i < stones.length; i++) {
laiyinlg
NORMAL
2019-08-16T18:31:31.838392+00:00
2019-08-30T06:02:20.695862+00:00
5,107
false
```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n int[] buckets = new int[1001];\n for (int i = 0; i < stones.length; i++) {\n buckets[stones[i]]++;\n }\n\n int slow = buckets.length - 1; //start from the big to small\n while (slow > 0) {\n\t\t// If ...
42
5
[]
16
last-stone-weight
JavaScript || Faster than 95% ||Easy to understand ||With comments
javascript-faster-than-95-easy-to-unders-qw0x
\n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n while(stones.length>1){\n stones.sort((a,b)=>
VaishnaviRachakonda
NORMAL
2022-04-07T13:41:20.908884+00:00
2022-04-07T13:41:20.908989+00:00
4,121
false
```\n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n while(stones.length>1){\n stones.sort((a,b)=>b-a); //sort the remaining stones in decending order;\n stones[1]=stones[0]-stones[1]; //smash the first and second stones ie the stones with largest ...
38
0
['JavaScript']
4