Problem · String

Most Unknown Elements (Part 3 :)

EasyOA

  • Most Unique Elements (Part 1 :D
  • Most Unique Elements (Part 2 :O
  • Most Unique Elements (Part 3 :3
  • If time allows, the company'd like us to finish Part 3 :)

    Implement the jaccard function.

    The Jaccard Similarity is a pair-wise comparison calculated with the formula:

    jaccard(A, B) = intersection(A, B) / union(A, B)

    The intersection is the set of characters that are present in both strings together, including repeats.

    The union is the smallest set that contains all characters found in either string, including repeats.

    Thanks a ton to the kind soul who shared the source!

    Examples
    01 · Example 1
    string1 = "baa"
    string2 = "abbc"
    return = 0.4
    intersection(S1, S2) = "ab" union(S1, S2) = "aabbc" J(S1, S2) = len("ab") / len("aabbc") = 2/5
    drafts saved locally
    public float jaccard(String string1, String string2) {
      // write your code here
    }
    
    string1"baa"
    string2"abbc"
    expected0.4
    sign in to submit