Skip to content

Practice Palindrome Rearrangement Queries

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

Hard#2983
LeetCode Problem

Palindrome Rearrangement Queries

Problem Statement

Given an even-length string s and queries [a, b, c, d], consider each query independently on the original string. You may rearrange the characters in s[a..b] within the first half and independently rearrange s[c..d] within the second half. Both ranges include their endpoints; characters outside them stay unchanged. Return one boolean per query indicating whether these rearrangements can make the whole string a palindrome.

Source: Palindrome Rearrangement Queries on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abcabc", queries = [[1,1,3,5],[0,2,5,5]]
Output
[true,true]

# Example 2

Input
s = "abbcdecbba", queries = [[0,2,7,9]]
Output
[false]

# Example 3

Input
s = "acbcab", queries = [[1,2,4,5]]
Output
[true]

Constraints

2 <= n == s.length <= 10^5
1 <= queries.length <= 10^5
queries[i].length == 4
ai == queries[i][0], bi == queries[i][1]
ci == queries[i][2], di == queries[i][3]
0 <= ai <= bi < n / 2
n / 2 <= ci <= di < n
n is even.
s consists of only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Palindrome Rearrangement Queries.

Review your practice with PhantomCodeAI

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