`{"id":"6d4c4112-f61b-4e76-b650-082421cc68a5","name":"Nim Game","description":"Two players Alice and Bob are playing a game. They have n piles. ith pile conatins arr[i] no. of coins. In each move a player can choose a pile and remove as many coins as he wants (minimum 1 coin). The player who removes the last set of coins from table will win. Alice goes first.","inputFormat":"The first line contains integer n, no. of piles.\r\nsecond line contains n integer containing number of coins in each pile.","outputFormat":"Print the winner (ALICE or BOB).","constraints":"1&lt;= n &lt;= 10^5\r\n1&lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws NumberFormatException, IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n1 2 3","sampleOutput":"BOB\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1191e2be-22c8-444b-988f-201dc78b143e","name":"Game Theory For Experts","slug":"game-theory-for-experts-930","type":0},{"id":"e15d91ef-6e16-48d5-ab94-31a70c26b00a","name":"Nim Game","slug":"nim-game","type":1}],"next":{"id":"2d5c3f5e-59c7-4590-9d77-9e54746a5bed","name":"Buddy Nim","type":1,"slug":"buddy-nim"},"prev":{"id":"165903b3-9bcf-4dba-9c15-b4b192f6b6f6","name":"One Two Three Game","type":1,"slug":"one-two-three-game"}}}`

# Nim Game

Two players Alice and Bob are playing a game. They have n piles. ith pile conatins arr[i] no. of coins. In each move a player can choose a pile and remove as many coins as he wants (minimum 1 coin). The player who removes the last set of coins from table will win. Alice goes first.

`{"id":"6d4c4112-f61b-4e76-b650-082421cc68a5","name":"Nim Game","description":"Two players Alice and Bob are playing a game. They have n piles. ith pile conatins arr[i] no. of coins. In each move a player can choose a pile and remove as many coins as he wants (minimum 1 coin). The player who removes the last set of coins from table will win. Alice goes first.","inputFormat":"The first line contains integer n, no. of piles.\r\nsecond line contains n integer containing number of coins in each pile.","outputFormat":"Print the winner (ALICE or BOB).","constraints":"1&lt;= n &lt;= 10^5\r\n1&lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws NumberFormatException, IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n1 2 3","sampleOutput":"BOB\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1191e2be-22c8-444b-988f-201dc78b143e","name":"Game Theory For Experts","slug":"game-theory-for-experts-930","type":0},{"id":"e15d91ef-6e16-48d5-ab94-31a70c26b00a","name":"Nim Game","slug":"nim-game","type":1}],"next":{"id":"2d5c3f5e-59c7-4590-9d77-9e54746a5bed","name":"Buddy Nim","type":1,"slug":"buddy-nim"},"prev":{"id":"165903b3-9bcf-4dba-9c15-b4b192f6b6f6","name":"One Two Three Game","type":1,"slug":"one-two-three-game"}}}`

Editor

# Nim Game

medium

Two players Alice and Bob are playing a game. They have n piles. ith pile conatins arr[i] no. of coins. In each move a player can choose a pile and remove as many coins as he wants (minimum 1 coin). The player who removes the last set of coins from table will win. Alice goes first.

## Constraints

1<= n <= 10^5 1<= arr[i] <= 10^8

## Format

### Input

The first line contains integer n, no. of piles. second line contains n integer containing number of coins in each pile.

### Output

Print the winner (ALICE or BOB).

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}3 1 2 3```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}BOB ```

Discussions

Show Discussion

Related Resources