1177. Can Make Palindrome from Substring Medium

@problem@discussion
#Hash Table#String#Bit Manipulation#Prefix Sum



1/**
2 * [1177] Can Make Palindrome from Substring
3 *
4 * 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.
5 * 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.
6 * Return a boolean array answer where answer[i] is the result of the i^th query queries[i].
7 * 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.
8 *  
9 * Example :
10 * 
11 * Input: s = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]
12 * Output: [true,false,false,true,true]
13 * Explanation:
14 * queries[0]: substring = "d", is palidrome.
15 * queries[1]: substring = "bc", is not palidrome.
16 * queries[2]: substring = "abcd", is not palidrome after replacing only 1 character.
17 * queries[3]: substring = "abcd", could be changed to "abba" which is palidrome. Also this can be changed to "baab" first rearrange it "bacd" then replace "cd" with "ab".
18 * queries[4]: substring = "abcda", could be changed to "abcba" which is palidrome.
19 * 
20 * Example 2:
21 * 
22 * Input: s = "lyb", queries = [[0,1,0],[2,2,1]]
23 * Output: [false,true]
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= s.length, queries.length <= 10^5
29 * 	0 <= lefti <= righti < s.length
30 * 	0 <= ki <= s.length
31 * 	s consists of lowercase English letters.
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/can-make-palindrome-from-substring/
37// discuss: https://leetcode.com/problems/can-make-palindrome-from-substring/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn can_make_pali_queries(s: String, queries: Vec<Vec<i32>>) -> Vec<bool> {
43        vec![]
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_1177() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.