MWC '15 #5 P3: French Words

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 0.3s
Memory limit: 256M

Problem type

Salarios77 and AndrewNitu are under suspicion of plagiarism, a serious crime at William Lyon Mackenzie CI. They were supposed to complete a project involving writing French words on a piece of paper in alphabetical order and presenting their definitions to the class. To see if they truly plagiarized, you are to write a program to determine how many unique words they share in common.

Input Specification

The first line contains two integers, N and M (1 \le N, M \le 10^4), the number of words in Salarios77's and AndrewNitu's respective projects.

The second line contains N strings, the words in the first list.

The third line contains M strings, the words in the second list.

It is guaranteed that each string consists only of characters a-z and has length at most 20.

Output Specification

Output the number of unique words they share in common.

Sample Input

4 4
a b c d
b c z zz

Sample Output



  • 1
    RAiNcalleER  commented on Oct. 1, 2021, 11:51 p.m. edited

    Hint: words are not distinct and should only count them once

  • 1
    ross_cleary  commented on May 24, 2020, 4:50 p.m.

    To clarify, the question is essentially asking to count the number of distinct words that occur at least once on both lines.

  • 0
    aeternalis1  commented on Aug. 10, 2017, 9:00 p.m. edit 2


    Assuming words in each essay aren't distinct, what would output be in this case:

    5 5

    aa bb bb cc ee

    aa bb ff gg hh

    • 0
      Tearful  commented on Oct. 20, 2017, 10:48 p.m.

      I'm guessing 2? Not sure :v