Palindrome Rearrangement Queries
hard · failed · 24.8% accepted · 98 likes · top 4%
hash table · string · prefix sum
Description
You are given a 0-indexed string s having an even length n.
You are also given a 0-indexed 2D integer array, queries, where queries[i] = [ai, bi, ci, di].
For each query i, you are allowed to perform the following operations:
- Rearrange the characters within the substring s[ai:bi], where 0 <= ai <= bi < n / 2.
- Rearrange the characters within the substring s[ci:di], where n / 2 <= ci <= di < n.
For each query, your task is to determine whether it is possible to make s a palindrome by performing the operations.
Each query is answered independently of the others.
Return a 0-indexed array answer, where answer[i] == true if it is possible to make s a palindrome by performing operations specified by the ith query, and false otherwise.
- A substring is a contiguous sequence of characters within a string.
- s[x:y] represents the substring consisting of characters from the index x to index y in s, both inclusive.
Example 1:
Example 2:
Example 3:
Solution