Algorithm · Uber · Hard
Problem: Total Cost to Convert All Substrings into Palindromes You are given a lowercase string s. For each substring s[l..r], where 0 <= l <= r < n, let cost(l, r) be the smallest number of single-character substitutions required to turn that substring into a palindrome. Each substitution changes one character in the substring to any other lowercase letter. Return the sum of these costs over all substrings: \[ \text{answer} = \sum_{0 \le l \le r < n} cost(l, r) \] Input A…
Checking your access…