Comments

Yes yes, actually the i in 2i+1 is the prev value in the sequence, hence the same thing. Sorry for the confusion.

See, if you just try it out by yourself, you'll notice that stairs are only possible for n values: 1,3,7,15, 31....., i.e 2i+1. And also the cells needed for a particular value of n, is actually n(n+1)/2 . So one could just loop while sum is less than x and updating n with 2n+1.

For this part consider the case to be : 1 1 1 2 3 1 4 5 Now since after 3 there is a 1, hence the player currently playing 3 will pick all of 3, hence the next player in turn is forced to pick 1, and hence the player picking 3 is still in control of the game. In short, the player whose turn it is, has to pick say x and x > 1, then that player is in control of the game, and will win the game

Consider the case :

1 1 1 2 3 4 5

The Second player will have the chance to pick the third element, i.e 2. So if the next element is not one the player will always choose (ai-1), so that it is ensured that the other player is forced to pick the one that is left at that place. If the next element would've been one, then our current player would've picked the complete (ai) so that the next player is forced to pick one. And hence if the starting element isn't one, the First player will always win.

Yep yep, I too did the same thing, counting the no. of consecutive ones in the prefix.