using
System;
using
System.Collections.Generic;
class
GFG {
static
HashSet<
string
> presentSubstring(
string
s,
int
k)
{
HashSet<
string
> st =
new
HashSet<
string
>();
int
n = s.Length;
for
(
int
i = 0; i < n; i++) {
string
s1 =
""
;
for
(
int
j = 0; j < k && i + j < n; j++) {
s1 += s[i + j];
st.Add(s1);
}
}
return
st;
}
static
string
smallestSubstring(
string
s,
int
k)
{
HashSet<
string
> st =
new
HashSet<
string
>();
st = presentSubstring(s, k);
int
index;
for
(
int
len = 1; len <= k; len++) {
string
t =
""
;
for
(
int
i = 0; i < len; i++)
t +=
'a'
;
while
(
true
) {
if
(st.Contains(t)==
false
) {
return
t;
}
index = len - 1;
while
(index >= 0 && t[index] ==
'z'
) {
t = t.Substring(0, index) +
'a'
+ t.Substring(index + 1);
index--;
}
if
(index >= 0) {
t = t.Substring(0, index)
+ Convert.ToChar((
int
)t[index] + 1)
+ t.Substring(index + 1);
}
else
break
;
}
}
return
"-1"
;
}
public
static
void
Main()
{
string
s =
"sdhaacbdefghijklmnopqrstuvwxyz"
;
int
K = 3;
Console.Write(smallestSubstring(s, K));
}
}