using
System;
class
GFG
{
static
int
MAX_LEN = 1005;
static
int
MAX_CHAR = 26;
static
int
[,] cnt =
new
int
[MAX_LEN,
MAX_CHAR];
static
void
preProcess(
string
s)
{
int
n = s.Length;
for
(
int
i = 0; i < n; i++)
cnt[i, s[i] -
'a'
]++;
for
(
int
i = 1; i < n; i++)
{
for
(
int
j = 0; j < 26; j++)
cnt[i, j] += cnt[i - 1, j];
}
}
static
int
findCharFreq(
int
l,
int
r,
char
c)
{
return
(cnt[r, c - 97] - cnt[l, c - 97]);
}
public
static
void
Main(
string
[] args)
{
string
s =
"geeksforgeeks"
;
int
Q = 4;
preProcess(s);
Console.WriteLine(findCharFreq(0, 5,
'e'
));
Console.WriteLine(findCharFreq(2, 6,
'f'
));
Console.WriteLine(findCharFreq(4, 7,
'm'
));
Console.WriteLine(findCharFreq(0, 12,
'e'
));
}
}