Skip to content

Commit e0ee592

Browse files
authored
Merge pull request ashutosh97#107 from maryheng/master
Added Get Longest Sorted Sequence question.
2 parents f28b1d9 + 60e3472 commit e0ee592

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Get Longest Sorted Sequence/answer.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def get_longest_sorted_sequence(words):
2+
count = 1
3+
total_letters = 0
4+
current = 0
5+
increasing_sum = 0
6+
is_sequence = True
7+
8+
if len(words) == 0:
9+
return 0
10+
else:
11+
current = len(words[0])
12+
13+
for i in range (1, len(words)):
14+
next = len(words[i])
15+
if current == next-1:
16+
print(current)
17+
# in sequence
18+
count += 1
19+
current = len(words[i])
20+
print(current)
21+
else:
22+
current = len(words[i])
23+
24+
return count
25+
26+
27+
# test cases
28+
print ('Actual :' + str(get_longest_sorted_sequence(['a', 'is', 'ape', 'in'])))
29+
print ()
30+
31+
32+
print ('Actual :' + str(get_longest_sorted_sequence(['apple', 'in', 'has', 'wed', 'code', 'rocks', 'bee'])))
33+
print ()
34+
35+
36+
print ('Actual :' + str(get_longest_sorted_sequence(['apple'])))
37+
print ()
38+
39+
print ('Actual :' + str(get_longest_sorted_sequence([])))
40+
print ()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The function takes in as its parameter a list called words that contains strings. This function first calculates the length of each word, and then returns the count whereby the sequence formed by the length of the words is in increasing order.
2+
3+
The function calculates the length of every string in the list. It has to then generate a sequence of numbers that are of increasing numberical value and return the length of the longest such sequence generated.

0 commit comments

Comments
 (0)