-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkata11.py
60 lines (20 loc) · 1.01 KB
/
kata11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Consecutive strings
#You are given an array strarr of strings and an integer k.
#Your task is to return the first longest string consisting of k consecutive strings taken in the array.
#Example:
#longest_consec(["zone", "abigail", "theta", "form", "libe", "zas", "theta", "abigail"], 2) --> "abigailtheta"
#n being the length of the string array, if n = 0 or k > n or k <= 0 return "".
#Note
#consecutive strings : follow one after another without an interruption
#I'm defining a Python function to determine the longest string if the original strings are combined for every k consecutive strings.
#The function takes two parameters, strarr and k.
def longest_consec(strarr, k):
n = len(strarr)
if k > n or k <= 0:
return ""
y = list()
for i in range(n):
x="".join(strarr[i:i+k])
y.append(x)
return max(y,key=len)
print(longest_consec(["wlwsasphmxx","owiaxujylentrklctozmymu","wpgozvxxiu"],2))