Jaccard Word Similarity
Yelp interview questions · Easy · Onsite round · 6 tests
You are handed two title strings, doc1 and doc2. Measure how alike
they are by computing the Jaccard similarity of their word sets.
Normalization rules
- Lowercase both inputs first.
- Break each string apart wherever a character is not a letter or digit.
- Throw away any empty pieces.
- Each title becomes a set of unique words; repeating a word adds nothing extra.
Formula
similarity = |intersection(tokens1, tokens2)| / |union(tokens1, tokens2)|Run your code with Ctrl+Enter to see results.