Minimum Characters to Palindrome
STRING
Problem
Given a string s
, calculate the minimum number of characters that need to be added at the beginning of s
to make the entire string a palindrome.
A palindrome is a string that reads the same backward as forward.
Examples
minCharsToPalindrome("abcba") // returns 0 // The string "abcba" is already a palindrome // so no characters need to be added. minCharsToPalindrome("abcd") // returns 3 // Adding "cba" at the beginning of "abcd" // forms the palindrome "cbabcd". */
Loading...