TopCoder problem "StudentEnrollment" used in TCHS08 Round 1 (Division I Level One)



Problem Statement

    

You are working as an intern at Talilulu University. Your task is to make a program that will help people to enroll in classes at the university. You are given a String[] names containing the names of the classes and a int[] spaces containing the number of spaces currently available in each class. The i-th element of names corresponds to the i-th element of spaces. You are also given a String[] queries containing the sequence of enrollment requests. Each element of queries is the name of the class in which a student wants to enroll.

Go through the elements of queries in order, and for each one, enroll the student in the class if there's room, or reject the request if the class does not exist or does not have any space available. Return a String[] containing the responses for each request. The i-th element of the String[] is the response to the i-th query. It should be "GOOD" if the enrollment is accepted, "NOT GOOD" if there is no available space in the requested class, or "DOES NOT EXIST" if the class does not exist (all quotes for clarity).

 

Definition

    
Class:StudentEnrollment
Method:checkClasses
Parameters:String[], int[], String[]
Returns:String[]
Method signature:String[] checkClasses(String[] names, int[] spaces, String[] queries)
(be sure your method is public)
    
 

Constraints

-names will contain between 0 and 50 elements, inclusive.
-names and spaces will contain the same number of elements.
-Each element of names will contain between 1 and 50 characters, inclusive.
-Each element of names will contain only uppercase letters ('A'-'Z').
-Each element of spaces will be between 0 and 100, inclusive.
-queries will contain between 0 and 50 elements, inclusive.
-Each element of queries will contain only uppercase letters ('A'-'Z').
-Each element of queries will contain between 1 and 50 characters, inclusive.
-All elements of names will be distinct.
 

Examples

0)
    
{"MATH", "ENGLISH"}
{1, 2}
{"ENGLISH", "MATH", "MATH"}
Returns: {"GOOD", "GOOD", "NOT GOOD" }
There is only one space available in MATH.
1)
    
{"MATH", "ENGLISH"}
{2, 0}
{"ENGLISH", "MATH", "MATH"}
Returns: {"NOT GOOD", "GOOD", "GOOD" }
2)
    
{"MATH", "ENGLISH"}
{2, 0}
{"ENGLISH", "FRENCH"}
Returns: {"NOT GOOD", "DOES NOT EXIST" }
3)
    
{"QCDTBCZICBJGQCCKIWXN",
 "LFAYDMBGLNXWNNDLHARQLYLWYJWMWOZ",
 "KPYATSAMTTKX",
 "HCNJGXTYCLPRENVMJPFEPVOYMTHXACMKTLGPQSEUJONXNZAVMR",
 "QADJYGPJ",
 "WVAGAZUCBG",
 "NHCKOMRNBSYRCKLNLCEOM",
 "SXXHKMNERPHPEQE",
 "JJUOCTOLFRJLJERFIXTCE",
 "SHQHEJGLUEWJIWPTSKTOPZTBVFFL"} 
{2, 1, 41, 5, 1, 0, 1, 13, 11, 9} 
{"NHCKOMRNBSYRCKLNLCEOM",
 "MTLRHPNKFNEXQQOWYERECRZXT",
 "QADJYGPJ",
 "WVAGAZUCBG",
 "EWWVWQZQNXEJGZJGZEVHKE",
 "QADJYGPJ",
 "IBQEMIBIGLVZLAOAYVPOMWZI",
 "JTFOEIPGOAHSGLYMQSCTVVMDINGURUWEZTHJFWUYAWBLAD",
 "ZRVMTHVAXCXJQPN",
 "QCDTBCZICBJGQCCKIWXN",
 "BVYUCAHSOBCBEFDEXWXFTKURXTIFDXXIDNBUPOPAWCBZHQY",
 "WVAGAZUCBG",
 "RVEJYNRBCOWRJBZHRTNQXROHWQOODMVDMVJDRNKWRGLXWWGPPW",
 "QADJYGPJ",
 "TYOMTKEVXMAVJBFBFDFOWARMZXSBUEMMQUWUNPSW",
 "SXXHKMNERPHPEQE",
 "JJUOCTOLFRJLJERFIXTCE",
 "SXXHKMNERPHPEQE",
 "SHQHEJGLUEWJIWPTSKTOPZTBVFFL",
 "JJUOCTOLFRJLJERFIXTCE",
 "QCDTBCZICBJGQCCKIWXN",
 "SXXHKMNERPHPEQE",
 "JJUOCTOLFRJLJERFIXTCE",
 "NJQBVNXCZZNLWM",
 "JJUOCTOLFRJLJERFIXTCE",
 "QADJYGPJ",
 "LFAYDMBGLNXWNNDLHARQLYLWYJWMWOZ"} 
Returns: 
{"GOOD",
"DOES NOT EXIST",
"GOOD",
"NOT GOOD",
"DOES NOT EXIST",
"NOT GOOD",
"DOES NOT EXIST",
"DOES NOT EXIST",
"DOES NOT EXIST",
"GOOD",
"DOES NOT EXIST",
"NOT GOOD",
"DOES NOT EXIST",
"NOT GOOD",
"DOES NOT EXIST",
"GOOD",
"GOOD",
"GOOD",
"GOOD",
"GOOD",
"GOOD",
"GOOD",
"GOOD",
"DOES NOT EXIST",
"GOOD",
"NOT GOOD",
"GOOD" }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=11153&pm=8195

Writer:

vlad_D

Testers:

PabloGilberto , Olexiy , ivan_metelsky , andrewzta

Problem categories:

Brute Force, String Manipulation