Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Mishki Playing Games problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Mishki, Playing Games problem solution Mishki loves playing games, so she asked her friend Hacker to join her in the Game of Stones. In this game, they have N sets of stones, numbered from 1 to N. Each set consists of Ai stones, where 1 <= i <= N.
 
In each turn, the player can select any of the sets containing at least 1 stone and have to reduce it to half of the present number of stones, i.e Ai/ 2 (Integer Division) from it, and in the case of a single stone, he/she has to empty the set by removing it.
 
As the game is really interesting, both will play this game on Q days. On each day, they will some select sets of stones numbered from l to r, where 1 <= l <= N and being a lover of the games, every day Mishki will be the first player to take the turn.
 
The one who won’t be able to play his/her turn in the game (i.e no stones left in the selected set of stones), will lose the game. You need to tell the winner of the game on each day if both the player will play optimally and take their turn alternatively.
 
 
HackerEarth Mishki Playing Games problem solution

 

 

HackerEarth Mishki Playing Games problem solution.

#include <iostream>
#include <cstdio>
#include <cassert>
#define ll long long
using namespace std;

const int ma = 1e6+6;
int a[ma];
ll prefix_sum[ma];

int check_log(int x)
{
int c=0;
while(x)
{
x>>=1;
c++;
}
return c;
}

int main()
{

int n,q;
scanf("%d%d",&n,&q);

for(int i=0;i<n;i++)
scanf("%d",&a[i]);

prefix_sum[0] = check_log(a[0]);
for(int i=1;i<n;i++)
{
prefix_sum[i] = prefix_sum[i-1]+ check_log(a[i]);
}

int l,r;
for(int i=0;i<q;i++)
{
scanf("%d%d",&l,&r);
l-=1;
r-=1;
if(l==0)
{
if(prefix_sum[r]%2)
printf("Mishkin");
else
printf("Hackern");
}
else
{
ll tp = prefix_sum[r]- prefix_sum[l-1];

if(tp%2)
printf("Mishkin");
else
printf("Hackern");
}
}
return 0;

}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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