TopCoder problem "SendingCards" used in TCHS SRM 48 (Division I Level One)

Problem Statement


When a major holiday is approaching, some people send cards to their friends. Unfortunately, some people forget a few of their friends, and are embarrassed to receive a card from them without having sent one. So, they follow by sending a card to those who were forgotten the first time around.

You are given a String[] friends, where the j-th character of the i-th element is a 'Y' or 'N', indicating whether or not person i sent a card to person j.

You are to return an int indicating the number of cards that get sent after the fact, when people realize they have forgotten one or more of their friends.



Method signature:int howMany(String[] friends)
(be sure your method is public)


-Character i of element i of friends will always be 'N'. In other words, it can be assumed that a person never sends a card to himself.


-friends will contain between 1 and 50 elements, inclusive.
-Each element of friends will contain exactly N characters, where N is the number of elements in friends.
-Each character of each element of friends will be 'Y' or 'N'.
-Character i of element i of friends will always be 'N'.


Returns: 1
Person 0 sent a card to person 1 initially. Since person 1 did not initially send a card to person 0, he sends one after the fact.
Returns: 3
Person 0 sent a card to both of his friends. Person 1 sent a card to person 2, but not to person 0 (whom he did receive a card from). Person 2 received 2 cards even though he didn't send any initially. Person 1 then has to send a card to person 0. Person 2 sends a card to both person 0 and person 1, for a total of three cards sent.
Returns: 2
Only person 0 sent out cards initially. Both of his friends then reciprocate.
Returns: 0
Person 0 and 1 mutually sent cards initially. Person 2 did not send or receive any cards. Thus, nobody received a card from anyone whom they did not originally send a card.
Returns: 0
There are four friends. However, none felt the need to send a Christmas card, and so none feel guilty either.

Problem url:

Problem stats url:




PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Brute Force, Simple Search, Iteration