Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use dynamic programming with memoization.
Notice that the first and last characters of a string are sufficient to determine the length of its concatenation with any other string.
Define dp[i][first][last] as the shortest concatenation length of the first i words starting with a character first and ending with a character last. Convert characters to their ASCII codes if your programming language cannot implicitly convert them to array indices.