TopCoder problem "GoodAndBadPostmen" used in TCHS SRM 30 (Division I Level Two)



Problem Statement

    

You work in a post office, where each worker is either a good postman or a bad postman. A good postman always delivers all his mail, and a bad postman always loses all his mail. Each day, you write down the names of all the postmen working that day. If all the mail gets delivered, you add that day to your white list. If at least one piece of mail gets lost, you add the day to your black list. You would like to determine the number of good and bad postmen in your office.

You will be given two String[]s, white and black. Each element of white represents a single day from your white list, and each element of black represents a single day from your black list. Each element of white and black is a single space delimited list of the names of the postmen who worked that day. The workers' names will not contain spaces. Return a int[] containing exactly 3 elements, where the first element is the number of good postmen, the second element is the number of bad postmen, and the third element is the number of undefined postmen. An undefined postman is a worker whose type cannot be determined with the information given.

 

Definition

    
Class:GoodAndBadPostmen
Method:whoIsWho
Parameters:String[], String[]
Returns:int[]
Method signature:int[] whoIsWho(String[] white, String[] black)
(be sure your method is public)
    
 

Constraints

-white and black will each contain between 0 and 50 elements, inclusive.
-Each element of white and black will contain between 1 and 50 characters, inclusive.
-Each element of white and black will not contain duplicate names.
-Each element of white and black will contain only lowercase letters ('a'-'z') and spaces.
-Each element of white and black will not contain trailing or leading spaces.
-Each element of white and black will not contain two consecutive spaces.
-Each element of black will contain at least one postman who is not in white.
 

Examples

0)
    
{"a b c", "c a d"}
{"a b c f", "c a d e"}
Returns: {4, 2, 0 }
There are 4 distinct postmen in the white list: a, b, c and d. They are definitely good since they always deliver all their mail. There is one day where postman f worked with 3 good postmen (a, b and c), and on that day, some mail was lost. Therefore, postman f must be bad. Similarly, postman e is bad.
1)
    
{"abc abcd"}
{"abcde"}
Returns: {2, 1, 0 }
2)
    
{"a b cd", "qq ee rre"}
{"a b c d e", "a cd t q", "a cd t", "qq ee q"}
Returns: {6, 2, 3 }
3)
    
{"a"}
{"a b c", "a b c d", "a b c d"}
Returns: {1, 0, 3 }
4)
    
{"alex", "serge", "vitalik"}
{}
Returns: {3, 0, 0 }
5)
    
{}
{"dmitry victor", "dmitry", "victor"}
Returns: {0, 2, 0 }
6)
    
{}
{}
Returns: {0, 0, 0 }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7288

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10654&pm=7288

Writer:

DStepanenko

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simulation