Hackerrank Hack 101 Aug 2013 Contest .

Hello everybody ,
Yesterday night i participated in hacker rank contest and i solved one problem , VROOK
My approach was something like this .

  1. Find a diff[n] ;
  2. where diff[i] = abs(p1[i]-p2[i]);
  3. Count the Odd number in diff array .
  4. if(count%2) {
  5. player 2 will win.
  6. }
  7. else {
  8. player 1 will win.
  9. }

I got Wrong answer , Please anybody who took participate in Last night Hackerrank contest please suggest me your approach .
You can view my solution here

Happy Coding!!!


The solution is to consider each of the columns as a pile in a nim game . The pile size will be abs(p1[i]- p2[i])-1 , And answer will be xor of these values. If it is non zero , player 2 wins , else player 1 wins.


@javadecoder thanks a lot now i got it … if you have any other questions links please share with us so we can practice on nim game problems.

1 Like