There is a group of friends that is not as close as it should be. Not everybody inside the group
likes everybody else. One of the friends has some important news that needs to be spread to
every member of the group. He has information on who would be willing to call each other and
has to develop a strategy to make sure all members of the group receive the news as soon as possible.
Each person can only call one friend each minute, and during that minute, he will transmit the news
along with the calling strategy that the receiver should follow. Any person that has already been
called is allowed to call other friends, but nobody can be on the phone (passing on or receiving
the news) with more than one other person during the same minute.
You will be given a String[] conn, where the jth character of the
ith element is 'Y' if the ith friend is willing to call the jth
friend, or 'N' otherwise. The 0th person (0-based) is the one that initially learns
about the news. Return the least number of minutes needed for the entire group to be aware of
the news. If it is impossible for this to happen, return -1.
|