Skip to content

Commit 78579b0

Browse files
author
Joseph Luce
authored
Update Longest_movie_title.md
1 parent 22c3e54 commit 78579b0

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

real_interview_questions/Google/Longest_movie_title.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
```
33
import copy
44
5-
def concat_longest_title(titles):
5+
def get_longest_title(titles):
66
adj_list = create_adj_list(titles)
77
global_visit = set()
88
longest_title = list()
@@ -19,7 +19,19 @@ def concat_longest_title(titles):
1919
memo)
2020
if len(local_result) > len(longest_title):
2121
longest_title = copy.deepcopy(local_result)
22-
return longest_title
22+
return concat_title(longest_title)
23+
24+
def concat_title(titles):
25+
if len(titles) == 0:
26+
return ''
27+
result = ''
28+
result = titles[0]
29+
for index in range(1, len(titles)):
30+
title = titles[index]
31+
sub_title = title[1:]
32+
result += sub_title
33+
return result
34+
2335
2436
def create_adj_list(titles):
2537
firstWord_to_titles_hash = dict()
@@ -62,12 +74,15 @@ def visit_title(title, stack, adj_list, local_visit, global_visit, memo):
6274
if len(stack) > len(result):
6375
result = copy.deepcopy(stack)
6476
stack.pop()
77+
local_visit.remove(title)
6578
memo[title] = result
6679
return result
6780
6881
Input = ['OF MICE AND MEN', 'BLACK MASS', 'MEN IN BLACK']
69-
Input = ['a b', 'b c', 'c d', 'c e', 'e f']
70-
Input = ['a b', 'b c', 'c a']
82+
#Input = ['a b', 'b c', 'c d', 'c e', 'e f']
83+
#Input = ['a b', 'b c', 'c a']
84+
Input = ['e f', 'c e', 'c d','b c', 'a b']
85+
#Input = ['c d','b c', 'a b', 'e f', 'c e']
7186
72-
print concat_longest_title(Input)
87+
print get_longest_title(Input)
7388
```

0 commit comments

Comments
 (0)