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
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Problem B Pikachu vs Team Meowstic and Helping Hand solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth ( Problem B) Pikachu vs Team Meowstic and Helping Hand problem solution Pikachu loves battling with other Pokemon. This time he has a team of N Meowstic to fight, ith of which has strength ai. He wants to fight with all of them K times. Team Meowstic came to know about this and now they have devised a strategy to battle against the mighty Pikachu.
 
All the N Meowstic stand in a straight line numbered from 1 to N. Before every round of battle, they simultaneously use a move, called Helping Hand. It changes the attacking power of Team Meowstic as follows:
 
The attacking power of first Meowstic remains ai.
The attacking power of remaining Meowstic changes as ai = ai | ai – 1 where 2 <= i <= N and A|B represents the bitwise OR of A and B 
For example, if the current attacking powers are [2,1,4,6,3], after using the Helping Hand, the powers change to [2,1|2,4|1,6|4,3|6], or [2,3,5,6,7].
 
Help Pikachu by finding the attacking powers of all Meowstic when he fights each of them for the last time, that is, for the Kth round.
 
 
HackerEarth ( Problem B ) Pikachu vs Team Meowstic and Helping Hand problem solution

 

 

HackerEarth ( Problem B ) Pikachu vs Team Meowstic and Helping Hand problem solution.

#include <bits/stdc++.h>

using namespace std;

int main(){
int N,K;
cin>>N>>K;
vector<int>x(N);
for(int i=0;i<N;i++){
cin>>x[i];
}
vector<int>last_set(30,INT_MIN);
vector<int>ans(N);
for(int i=0;i<N;i++){
for(int j=0;j<30;j++){
if((x[i]>>j)&1)last_set[j]=i;
if(i<=K+last_set[j])ans[i]|=(1<<j);
}
}
for(auto i:ans)cout<<i<<" ";

}
 

Second solution

n,k = map(int, raw_input().split())
arr = map(int, raw_input().split())

ans = [0 for __ in xrange(r)]
for b in xrange(30):
ds = -1
for i in xrange(n):
if arr[i]&1: ds = i+k
arr[i] >>= 1
ans[i] |= (i<=ds)<<b

print " ".join(map(str, ans))
 
 
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