Skip to content

Practice Can Make Palindrome from Substring

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1177
LeetCode Problem

Can Make Palindrome from Substring

Problem Statement

You are given a string s and array queries where queries[i] = [lefti, righti, ki]. We may rearrange the substring s[lefti...righti] for each query and then choose up to ki of them to replace with any lowercase English letter. If the substring is possible to be a palindrome string after the operations above, the result of the query is true. Otherwise, the result is false. Return a boolean array answer where answer[i] is the result of the ith query queries[i]. Note that each letter is counted individually for replacement, so if, for example s[lefti...righti] = "aaa", and ki = 2, we can only replace two of the letters. Also, note that no query modifies the initial string s. Example :

Source: Can Make Palindrome from Substring on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]
Output
[true,false,false,true,true]

# Example 2

Input
s = "lyb", queries = [[0,1,0],[2,2,1]]
Output
[false,true]

Constraints

1 <= s.length, queries.length <= 10^5
0 <= lefti <= righti < s.length
0 <= ki <= s.length
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Can Make Palindrome from Substring.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.