egonSchiele / grokking_algorithms

Code for the book Grokking Algorithms (https://amzn.to/29rVyHf)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Longest common substring wrongly coded.

To-heeb opened this issue · comments

The longest common substring is wrongly in Python coded and throws an error anytime it runs, this should be prioritized since it is a core part of the book.

dp_table_blue = ["b", "l", "u", "e"]
dp_table_clues = ["c", "l", "u", "e", "s"]
dp_table = [[0 for i in range(len(dp_table_blue))] for i in range(len(dp_table_clues))] # (5,4)
print(dp_table)

for i in range(0, len(dp_table_blue)):
    for j in range(0, len(dp_table_clues)):
        if dp_table_clues[j] == dp_table_blue[i]:
            dp_table[i][j] = dp_table[i-1][i-1] + 1

print(dp_table)

copy this code and try to run it here https://onecompiler.com/python or click this link https://onecompiler.com/python/3znsmgdbr to run it directly to get the errors.