← Back to challenges

Minimum Steps to a Palindrome

JavaScriptHardstringsalgorithms

Instructions

Given an incomplete palindrome as a string, return the minimum letters needed to be added on to the end to make the string a palindrome.

Examples

minPalindromeSteps("race") ➞ 3
// Add 3 letters: "car" to make "racecar"

minPalindromeSteps("mada") ➞ 1
// Add 1 letter: "m" to make "madam"

minPalindromeSteps("mirror") ➞ 3
// Add 3 letters: "rim" to make "mirrorrim"

Notes

Trivially, words which are already palindromes should return 0.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.