Skip to content

Commit 9ae6e6f

Browse files
substring-with-k-chars
1 parent e462e40 commit 9ae6e6f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def substr(mystr, k):
2+
if mystr == None or k == 0:
3+
return 0
4+
ls = list()
5+
for i in range(len(mystr) - (k-1)):
6+
ls.append(mystr[i:i+k]) # set to remove duplicate k length strings
7+
8+
res = set()
9+
for ele in ls:
10+
if len(set(ele)) == k:
11+
res.add(ele)
12+
return len(res)
13+
14+
#ans = set() # set to eliminate strings having duplicate characters
15+
#xt = list(st)
16+
#for ele in xt:
17+
# if len(set(ele)) == k:
18+
# ans.add(ele)
19+
#return len(ans)
20+
21+
n = int(input())
22+
for i in range(n):
23+
mystr = str(input())
24+
k = int(input())
25+
print(substr(mystr, k))
26+

0 commit comments

Comments
 (0)