Design Gurus Logo
Valid Palindrome III (hard)

Problem Statement

Given a string s and integer k, return true if string can be converted into the palindromic string after removing at most k characters. Otherwise, return false.

Examples

  • Example 1:
    • Input: s = "radar", k = 1
    • Expected Output: true
    • Justification: The string "radar" is already a palindrome, so no characters need to be removed. Since 0 (which is less than 1) characters are removed, the output is true.
  • Example 2:
    • Input: s = "abracadabra", k = 5
    • Expected Output: true
    • Justification: By removing the characters 'b', 'c', 'd', and 'b' , the string becomes "araaara", which is a palindrome. We've removed exactly 5 characters, so the output is true.
  • Example 3:
    • Input: s = "data", k = 0
    • Expected Output: false
    • Justification: It's impossible to form a palindrome by removing zero characters from "data", so the output is false.

Constraints:

  • 1 <= s.length <= 1000
  • s consists of only lowercase English letters.
  • 1 <= k <= s.length

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory