using
System;
public
class
Query_Subsequence
{
static
int
MAX = 10000;
static
int
CHAR_SIZE = 26;
static
void
precompute(
int
[,]mat,
string
str,
int
len)
{
for
(
int
i = 0; i < CHAR_SIZE; ++i)
mat[len, i] = len;
for
(
int
i = len - 1; i >= 0; --i)
{
for
(
int
j = 0; j < CHAR_SIZE;
++j)
mat[i, j] = mat[i + 1, j];
mat[i, str[i] -
'a'
] = i;
}
}
static
bool
query(
int
[,]mat,
string
str,
int
len)
{
int
pos = 0;
for
(
int
i = 0; i < str.Length; ++i)
{
if
(mat[pos,str[i] -
'a'
] >= len)
return
false
;
else
pos = mat[pos,str[i] -
'a'
] + 1;
}
return
true
;
}
public
static
void
Main()
{
string
S=
"geeksforgeeks"
;
int
len = S.Length;
int
[,] mat =
new
int
[MAX,CHAR_SIZE];
precompute(mat, S, len);
string
get
= query(mat,
"gg"
, len)?
"Yes"
:
"No"
;
Console.WriteLine(
get
);
get
= query(mat,
"gro"
, len)?
"Yes"
:
"No"
;
Console.WriteLine(
get
);
get
= query(mat,
"gfg"
, len)?
"Yes"
:
"No"
;
Console.WriteLine(
get
);
get
= query(mat,
"orf"
, len)?
"Yes"
:
"No"
;
Console.WriteLine(
get
);
}
}