Jaccard Similarity Threshold
InterviewTime limit1sMemory limit512 MB
Given two small sets of digits, decide whether their Jaccard similarity is greater than 0.5.
- Level
Easy2 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
The Jaccard similarity coefficient measures how similar two sets are. For two sets and , the coefficient is the size of the intersection divided by the size of the union, that is . For example, if and , then .
Every element of a set is an integer between 0 and 9, and no set holds more than 10 elements. Given two sets and , compute and print 1 when , or 0 when .
Input
The first line contains the number of test cases ().
Each test case consists of three lines. The first line contains and , the number of elements of and the number of elements of (). The second line contains the elements of and the third line contains the elements of , separated by spaces. Every element is an integer between 0 and 9, and the same value never appears twice inside one set.
Output
For each test case, print 1 if and 0 if , one answer per line.