Students in a science class are simulating the spread of communicable disease with a simple experiment. At the start of the experiment, each student receives a vial of liquid, which may or may not be contaminated. (It is not known whether or not it is contaminated.) The vials are numbered 0 through n-1, where n is the number of students participating.
In several successive rounds of contact, each student adds a sample from their vial to that of another student, or chooses to abstain from contact by adding the sample back to his own vial. These rounds of contact are repeated several times, with each round being completed before the next begins. Note that during each round, all contact happens simultaneously (you can think about it as some liquid being taken out of each vial before any is added to any vial). After several rounds of contact, each student's vial is tested for the presence of the contamination, to visually see just how quickly and easily a disease can spread.
You are given a String[], contact, indicating to whom samples were given in each round. The i-th element of contact indicates the vial to whom student i gave a sample in each round. Each element of contact will be a space-delimited list of integers with no leading zeros. Each number represented will be between 0 and n-1, where n is the number of students. You are also given a String, results. Each character of results will be either 'C' or 'N', representing "contaminated" or "not contaminated". The zero-based index of each character corresponds to the number on the vial.
We want to determine, to the best of our ability, which vials were originally contaminated. You are to return a String indicating this information. Each character of the return value should be 'C', 'N', or 'I', indicating vials that were definitely contaminated, definitely not contaminated, or if it is inconclusive. The i-th character of the return value corresponds to the i-th vial. If the value of results is impossible given the data in contact, your method should return "INVALID", to indicate that something must have gone wrong in the experiment.
|