×

# Explain the approach applied in the solution

 0 Please explain this solution for the problem. asked 26 Nov '17, 21:32 37●5 accept rate: 0%

 2 In this problem, basically there are three players. one player is watching other two players play. So, it is natural that the third person, who is watching the game, cannot win. We are given a sequence consisting of N integers stating that ith game is won by A[i]. We just have to check that at no point should the spectator win. :) The solution You mentioned create a boolean array of size 3. if player[i] = true, ith player is playing right now. Initially first two players are playing. So play[0] = true and play[1] = true Then, in loop, he check if the play[A[i]-1] == false. This line means that the winner as per sequence is playing or not. if play[A[i]-1] == false, sequence is not valid. otherwise he changed status of all playing players to false, and the third player, whose play[i] == false, set play[i] = true Then, as the problem said, winner play the next round, he set play[a[i]-1] = true And this continues till N. and print answer. :) answered 26 Nov '17, 22:53 3.9k●28●95 accept rate: 22% Thank you. (27 Nov '17, 00:28) No Problem mate. :) (27 Nov '17, 01:29)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×682

question asked: 26 Nov '17, 21:32

question was seen: 1,140 times

last updated: 27 Nov '17, 01:29