java.lang.Object
g1101_1200.s1177_can_make_palindrome_from_substring.Solution

public class Solution extends Object
1177 - Can Make Palindrome from Substring.<p>Medium</p> <p>You are given a string <code>s</code> and array <code>queries</code> where <code>queries[i] = [left<sub>i</sub>, right<sub>i</sub>, k<sub>i</sub>]</code>. We may rearrange the substring <code>s[left<sub>i</sub>&hellip;right<sub>i</sub>]</code> for each query and then choose up to <code>k<sub>i</sub></code> of them to replace with any lowercase English letter.</p> <p>If the substring is possible to be a palindrome string after the operations above, the result of the query is <code>true</code>. Otherwise, the result is <code>false</code>.</p> <p>Return a boolean array <code>answer</code> where <code>answer[i]</code> is the result of the <code>i<sup>th</sup></code> query <code>queries[i]</code>.</p> <p>Note that each letter is counted individually for replacement, so if, for example <code>s[left<sub>i</sub>&hellip;right<sub>i</sub>] = &ldquo;aaa&rdquo;</code>, and <code>k<sub>i</sub> = 2</code>, we can only replace two of the letters. Also, note that no query modifies the initial string <code>s</code>.</p> <p><strong>Example :</strong></p> <p><strong>Input:</strong> s = &ldquo;abcda&rdquo;, queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]</p> <p><strong>Output:</strong> [true,false,false,true,true]</p> <p><strong>Explanation:</strong></p> <p>queries[0]: substring = &ldquo;d&rdquo;, is palidrome.</p> <p>queries[1]: substring = &ldquo;bc&rdquo;, is not palidrome.</p> <p>queries[2]: substring = &ldquo;abcd&rdquo;, is not palidrome after replacing only 1 character. q</p> <p>ueries[3]: substring = &ldquo;abcd&rdquo;, could be changed to &ldquo;abba&rdquo; which is palidrome. Also this can be changed to &ldquo;baab&rdquo; first rearrange it &ldquo;bacd&rdquo; then replace &ldquo;cd&rdquo; with &ldquo;ab&rdquo;.</p> <p>queries[4]: substring = &ldquo;abcda&rdquo;, could be changed to &ldquo;abcba&rdquo; which is palidrome.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;lyb&rdquo;, queries = [[0,1,0],[2,2,1]]</p> <p><strong>Output:</strong> [false,true]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length, queries.length <= 10<sup>5</sup></code></li> <li><code>0 <= left<sub>i</sub> <= right<sub>i</sub> < s.length</code></li> <li><code>0 <= k<sub>i</sub> <= s.length</code></li> <li><code>s</code> consists of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • canMakePaliQueries

      public List<Boolean> canMakePaliQueries(String s, int[][] queries)