All problems
N-gram Overlap Dedup
Problem
Return the Jaccard similarity between the sets of whitespace-token n-grams of strings a and b. Return 0.0 when n <= 0 or either string produces no n-grams.
Test cases
case 1
in: ["the cat sat","the cat ran",1]
expected: 0.5
case 2
in: ["a b c","a b c",2]
expected: 1
case 3
in: ["a b","c d",1]
expected: 0
case 4
in: ["a b c d","a b c e",3]
expected: 0.3333333333333333
Starter codePython
def ngram_jaccard(a, b, n):
# Your code here
pass4 test cases · run your code against them in the editor