Minimum Insertion Steps to Make a String Palindrome - LeetCode 1312 - Python Solution

preview_player
Показать описание
Solution Blog: (sign into leetcode to view)

Use 2 pointers.

left pointer that starts @ index 0
right pointer that starts @ last index
If they point to the same value - move pointers inward.

If they don't add 1 and take the minimum of the two possible paths:

increment left pointer by 1
decrement right pointer by 1
When the left pointer passes the right pointer you've finished processing so return 0.

Time complexity: O(N^2)
Space complexity: O(N^2)

Hope this helped! Have an awesome day!
#python #leetcode #tutorial
Рекомендации по теме
Комментарии
Автор

so much easier to follow than others sources i found. this channel will grow!

joshuablanchard
Автор

Hey can this be written in tabulation. I mean in the same way that you wrote the memoization?
Because i tried but couldn't able to make it

dharanyuvi
join shbcf.ru