Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: What is the minimum number of characters to insert to make 'leetcode' a palindrome? Use length minus longest palindromic subsequence (LPS = 3, for example 'eee'). Run the code.

Problem: What is the minimum number of characters to insert to make 'leetcode' a palindrome? Use length minus longest palindromic subsequence (LPS = 3, for example 'eee'). Run the code.
s = 'leetcode'
print(len(s) - 3)
What is printed?
  1. A. 3
  2. B. 4
  3. C. 5
  4. D. 6

Correct answer: C. 5

The longest palindromic subsequence of 'leetcode' is 3 (for example 'eee'), so 8 - 3 = 5 insertions are needed.

More Coding Interview Problems questions

Exams that ask this topic