DiffPush Tier Dynamic Programming · DP on Strings O(n^2) · O(n^2)
A legacy router stores configuration keys that must read as palindromes for its checksum logic to accept them. Upgrades may only prepend or append characters — one insertion per step. The migration tool computes the fewest insertions that turn each legacy key into a valid palindrome before the firmware swap.
Input: A string s.
Output: Return the minimum number of characters to insert (anywhere) so that s becomes a palindrome.
1 <= len(s) <= 500s consists of lowercase English lettersInput: {"s":"zzazz"}
Output: 0
The key is already a palindrome.
Input: {"s":"mbadm"}
Output: 2
"mbdadbm" or "mdbabdm" both need two insertions.