// C# program for the above approach
using System;
class GFG{
// Function to find whether String can be
// made palindromic or not for each queries
static void canMakePaliQueries(String str,
int [,]Q)
{
int n = str.Length;
// To store the count of ith character
// of subString str[0...i]
int [,]dp = new int[26, n];
for(int i = 0; i < 26; i++)
{
// Current character
char currentChar = (char)(i + 'a');
for(int j = 0; j < n; j++)
{
// Update [,]dp on the basis
// recurrence relation
if (j == 0)
{
dp[i,j] = (str[j] ==
currentChar) ? 1 : 0;
}
else
{
dp[i,j] = dp[i, j - 1] +
((str[j] ==
currentChar) ? 1 : 0);
}
}
}
// For each queries
for(int l = 0; l < Q.GetLength(0);l++)
{
int []query = GetRow(Q,l);
int left = query[0];
int right = query[1];
int k = query[2];
// To store the count of
// distinct character
int unMatchedCount = 0;
for(int i = 0; i < 26; i++)
{
// Find occurrence of i + 'a'
int occurrence = dp[i, right] -
dp[i, left] +
(str[left] ==
(i + 'a') ? 1 : 0);
if (occurrence % 2 == 1)
unMatchedCount++;
}
// Half the distinct Count
int ans = unMatchedCount / 2;
// If half the distinct count is
// less than equals to K then
// palindromic String can be made
if (ans <= k)
{
Console.Write("YES\n");
}
else
{
Console.Write("NO\n");
}
}
}
public static int[] GetRow(int[,] matrix, int row)
{
var rowLength = matrix.GetLength(1);
var rowVector = new int[rowLength];
for (var i = 0; i < rowLength; i++)
rowVector[i] = matrix[row, i];
return rowVector;
}
// Driver Code
public static void Main(String[] args)
{
// Given a String str
String str = "GeeksforGeeks";
// Given Queries
int [,]Q = { { 1, 5, 3 },
{ 5, 7, 0 },
{ 8, 11, 3 },
{ 3, 10, 5 },
{ 0, 9, 5 } };
// Function call
canMakePaliQueries(str, Q);
}
}
// This code is contributed by Princi Singh