Here is link of problem https://www.youtube.com/watch?v=HdRgnzRk56Q&t=777s
Problem Statement : Lets suppose we have n piles of stone each having stones a[i] 1<=i<=n
.We can play turn by turn and we start at first and in one move we can convert a pile into two non empty piles.consider both player are playing optimally . who will win the game ?
According to @kingofnumbers solution , if biggest number is not of type (2^k)-1 then we will always win else we will lose.
I didn’t get it. Instead i thought a different solution.
Here it is : We will add the sum of all coins and number of piles and now we will check if its even or odd . if its even then first player will lose else will win.
Lets consider sum1 shows sum of all coins of piles.
initially number of piles are n . now in one move any player will make two piles out one pile so sum1 willl remain constant while n will increase by 1 thus parity of sum2 is changing in every move.
we know in final state all piles will be of containing 1 coin each. so sum2=sum1+sum1=2*sum1;
so if sum2 is even player who is playing will lose else will won .
can you help me to find what’s wrong in my approach ?