Coin Game Winner Problem Statement

Two players 'X' and 'Y' are participating in a coin game. Starting with 'N' coins, players alternate turns, with 'X' starting first. On each turn, a player has three choices: pick exactly 'A' coins, 'B' coins, or 1 coin. The player unable to make a move loses. Determine the winner if both players play optimally.

Input:

The first line contains an integer ‘T’ representing the number of test cases.
Each test case consists of three integers: ‘N’ (the number of coins), ‘A’, and ‘B’ (the number of coins that can be picked on a turn).

Output:

Return 1 if X wins the game, and return 0 if Y wins for each test case.

Example:

Input:
2
3 2 1
4 3 2

Output:
1
0

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 105

Note: Implement only the function to determine the winner; no need to handle input/output operations.

AnswerBot
4mo

Determine the winner of a coin game where players take turns picking coins optimally.

  • Players take turns picking 'A', 'B', or 1 coin each turn

  • The player unable to make a move loses

  • Implement a function ...read more

Help your peers!
Select
Add answer anonymously...

Nagarro Software Developer interview questions & answers

A Software Developer was asked 3mo agoQ. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
A Software Developer was asked 3mo agoQ. Given the root of a binary search tree, and an integer k, return the kth smalles...read more
A Software Developer was asked 5mo agoQ. What is abstraction in Java?

Popular interview questions of Software Developer

A Software Developer was asked 3mo agoQ1. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
A Software Developer was asked 3mo agoQ2. Given the root of a binary search tree, and an integer k, return the kth smalles...read more
A Software Developer was asked 5mo agoQ3. What is abstraction in Java?
Nagarro Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits