There was a question in topcoder.
Question:
Three kids are playing the following game: A word is written on a sheet of paper, and one after another, the players take turns adding letters to the word. During each turn, a player must add a single letter to either the beginning or the end of the word. If a player cannot add a letter during his turn, the game ends and that player is declared the loser.
During the game, a player might cheat by making an illegal move. Any move where the player does not add exactly one letter to either the beginning or the end of the word is considered illegal. The only exception is the last move of the game, when the loser adds no letters to the word. Given the log of the game, you must determine whether any of the players cheated.
You are also given the String[]s first, second, and third, containing the chronological lists of words seen by each of the players at the beginning of their turns. Element 0 of first is therefore the original word, element 0 of second is the word after the first player makes his first move, element 0 of third is the word after the second player makes his first move, etc. Return 1, 2, or 3 if the first, second, or third player, respectively, cheated. If multiple players cheated, return the player who cheated first. If nobody cheated, return -1.
Input:
{"e","ello"}
{"el","hello"}
{"ell","ello"}
Output:
Returns: 2
Reason:
The second player saw "hello" before making his second move, and then, the third player saw "ello" immediately after the second player made his second move. Therefore, the second player cheated on his second move because "hello" -> "ello" is not a legal move.
I didn't understand the question itself. if someone understood how to do this question, Please help me .