data-structures · intermediate · ~15 min
Fewest inserts to make a string a palindrome.
Implement:
int min_insertions_palindrome(const char *s);
Return the minimum number of characters to insert anywhere so that s becomes a palindrome.
A string.
Minimum insertions.
Answer is len - LPS(s).
#include <stddef.h>
/* Minimum characters to insert anywhere to make s a palindrome. */
int min_insertions_palindrome(const char *s){ (void)s; return -1; }
Trying to reason about insertions directly instead of via the palindromic subsequence.
A palindrome needs 0; empty/single needs 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.