Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Fuzzy String Matching by catloverss
def fuzzy_string_match(str1: str, str2: str, threshold: int) -> bool:
len1, len2 = len(str1), len(str2)
# Create DP table
dp = [[0]*(len2+1) for _ in range(len1+1)]
# Initialize first row and column
for i in range(len1+1):
dp[i][0] = i
for j in range(len2+1):
dp[0][j] = j
# Fill the table
for i in range(1, len1+1):
for j in range(1, len2+1):
if str1[i-1] == str2[j-1]:
dp[i][j] = dp[i-1][j-1]
else:
dp[i][j] = 1 + min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1])
# The edit distance is in dp[len1][len2]
return dp[len1][len2] <= threshold
Dec. 5, 2025
Comments: