In the game of Musical Chairs, n players walk around a circle of
n-1 chairs while music plays on the stereo. When the music stops,
everyone hurries to claim a chair. The player who is left standing gets
knocked out of the game.
You are given a String[] playerNames containing the names of the players, ordered according to
their position at the start of the game, such as the following.
{"Emma Sue", "Billy Bob Thornton", "Joe", "Cassius Clay"}
You are also given a String chairs describing the arrangement of
chairs with an 'h' (lowercase letter H) for each chair and exactly one
'.' (period) indicating a gap. The i-th character of chairs corresponds to the i-th element
of playerNames. For instance, the chairs might be arranged
as follows.
"hh.h"
The player by the gap is the one who gets knocked out. For example,
if the four players above are in their starting order when the music
stops, then Joe gets knocked out.
For each second of music, the players advance one position. From the
original order shown above, for example, the players' order changes to
the following after one second.
{"Cassius Clay", "Emma Sue", "Billy Bob Thornton", "Joe"}
Given an int seconds specifying the number of seconds that the
music is played, return the name of the player who gets knocked out.
|