-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel9.py
More file actions
30 lines (24 loc) · 845 Bytes
/
level9.py
File metadata and controls
30 lines (24 loc) · 845 Bytes
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
#For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be
# allLongestStrings(inputArray) = ["aba", "vcd", "aba"].
def allLongestStrings(inputArray):
map = []
counter, max_elm = 0, 0
for i, word in enumerate(inputArray):
for j in word:
counter += 1
if counter > max_elm:
max_elm = counter
map = []
map.append(word)
elif counter == max_elm:
map.append(word)
counter = 0
return map
#alternate solution
# def allLongestStrings(inputArray):
# max_str_len = len(inputArray[0])
# for i in range(len(inputArray)):
# if len(inputArray[i])>max_str_len:
# max_str_len = len(inputArray[i])
# res = [strings for strings in inputArray if len(strings==max_str_len]
# return res