Get Time

   Problem Statement  

 Problem Statement for CoinFlipsDiv2

Problem Statement


You have n coins, labeled 0 through n-1. Each of the coins shows either heads or tails. You are given the states of all coins in the String state with n characters. For each i, state[i] is 'H' if coin i shows heads, or 'T' if it shows tails.

The coins are laid out in a row, ordered from coin 0 to coin n-1. A coin is called interesting if it differs from at least one of its neighbors. (For example, a coin that shows heads is interesting if at least one of its neighbors shows tails.) Return the number of interesting coins.



Method signature:int countCoins(String state)
(be sure your method is public)


-The value of n is not given explicitly. Instead, you can determine it as the number of characters in state.


-state will have between 1 and 50 elements, inclusive.
-Each character of state will be either 'H' or 'T'.


Returns: 2
Coin 0 is interesting because it shows heads and its only neighbor shows tails. Similarly, coin 1 is interesting because it shows tails and its only neighbor shows heads. Thus, the answer is 2.
Returns: 0
In this test case there is a single coin. It has no neighbors, and therefore it has no different neighbors. This means that the coin is not interesting.
Returns: 0
None of these coins are interesting, because each of them is only adjacent to coins that show the same side.
Returns: 3
Here, the three interesting coins are coins 1, 2, and 3. (Remember that the indices are 0-based.)
Returns: 12

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 681 Round 1 - Division II, Level One