Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerRank A Chessboard Game problem solution

YASH PAL, 31 July 202426 January 2026

In this HackerRank A Chessboard Game problem solution, we have given the initial coordinates of the players’ coins, assuming optimal play, determine which player will win the game.

HackerRank A Chessboard Game problem solution

HackerRank A Chessboard Game problem solution in Python.

t = int(input())
for _ in range(t):
    x , y = map(int,input().split())
    if x%4==0 or x%4 ==3 or y%4==0 or y%4==3:
        print("First")
    else:
        print("Second")

A Chessboard Game problem solution in Java.

import java.io.*;
import java.util.*;

public class Solution {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    for(int i = 0; i < n; i++) {
      int playerX = in.nextInt();
      int playerY = in.nextInt();
      System.out.println(findWinner(playerX, playerY));
    }
  }

  public static String findWinner(int x, int y) {
    return (x-1)%4<2 && (y-1)%4<2? "Second" : "First";
  }
}

Problem solution in C++.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int t, z, x, y;
    cin >> t;
    for (z=0; z<t; z++)
    {
        cin >> x >> y;
        x %= 4;
        y %= 4;
        if (x==0 || x==3 || y==0 || y==3) cout << "Firstn";
        else                              cout << "Secondn";
    }
    return 0;
}

Problem solution in C.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int t, m, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d %d", &m, &n);
        int i = m % 4;
        int j = n % 4;
        if ((i == 1 || i == 2) && (j == 1 || j == 2)) {
            printf("Secondn");
        } else {
            printf("Firstn");
        }
    }
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    return 0;
}

Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes