You are not logged in. Please login at to post your questions!


Explain the approach applied in the solution

Please explain this solution for the problem.

asked 26 Nov '17, 21:32

gautamcse27's gravatar image

accept rate: 0%

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

taran_1407's gravatar image

accept rate: 22%

Thank you.

(27 Nov '17, 00:28) gautamcse272★

No Problem mate. :)

(27 Nov '17, 01:29) taran_14076★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • 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:


question asked: 26 Nov '17, 21:32

question was seen: 1,140 times

last updated: 27 Nov '17, 01:29