#K74282. Jaccard Similarity of Purchase Histories
Jaccard Similarity of Purchase Histories
Jaccard Similarity of Purchase Histories
In this problem, you are given the purchase histories of two users. Each purchase history is represented as a list of product IDs. Your task is to compute the Jaccard similarity coefficient between these two lists. The Jaccard similarity coefficient is defined as
where (A) and (B) are the sets of products from the first and second user, respectively. The result should be rounded to 6 decimal places.
inputFormat
Input is given from standard input (stdin) and consists of three lines. The first line contains two integers (n) and (m), the number of products purchased by the first and second user respectively. The second line contains (n) space-separated integers representing the products purchased by the first user. The third line contains (m) space-separated integers representing the products purchased by the second user.
outputFormat
Output to standard output (stdout) the Jaccard similarity coefficient, rounded to 6 decimal places.## sample
5 4
1 2 3 4 5
4 5 6 7
0.285714
</p>