• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
December 21, 2023 |1.2K Views
PROBLEM OF THE DAY : 20/12/2023 | Modified Game of Nim
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Bit Magic but also build up problem-solving skills.

In this problem, given an array A of n elements. There are two players player 1 and player 2.
A player can choose any of element from an array and remove it. If the bitwise XOR of all remaining elements equals 0 after removal of the selected element, then that player loses. Find out the winner if player 1 starts the game and they both play their best.

Example :

Input: 
n = 3
A = [3, 3, 2]
Output: 
2

Explaination: 
Optimal removal of values are 3, 2, 3 sequentially. Then the array is empty. So player 2 wins.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/variation-in-nim-game4317/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/13ba0eb9-f554-4444-82ce-ac3f20465923