We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e462e40 commit 9ae6e6fCopy full SHA for 9ae6e6f
count_substrings_k_distinct_characters.py
@@ -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