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 Rubik Square problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Rubik’s Square problem solution Raj has bought a new Rubik’s Cube and he try to solve it day and night. Seeing this , Vikas tried to help Raj by giving him problem based on cube Rotation . To make it easier for Raj , As Raj is a beginner Vikas gave problem in square matrix instead of cube. The problem is as follows :
 
Vikas has N*N array of different numbers. Now he rotates the rows and columns . Raj has to stay focused and tell Vikas what should be output of matrix after R Rows Rotation and C columns rotation.
 
Raj is now more confused then ever from the above problem. Help him to find the answer.
 
 
HackerEarth Rubik's Square problem solution

 

 

HackerEarth Rubik’s Square problem solution.

using namespace std;

int main(){ // freopen("sampleinput.txt","r",stdin); // freopen("sampleoutput.txt","w",stdout); int n,rr,cc; cin>>n>>rr>>cc; int a[n][n]; for(int i=0;i>a[i][j]; } } int r[n],c[n]; memset(r,0,sizeof(r)); memset(c,0,sizeof(c));

for(int i=0;i<rr;i++){
int t;
cin>>t;
r[t-1]++;
r[t-1]=r[t-1]%n;
}

for(int i=0;i<cc;i++){
int t;
cin>>t;
c[t-1]++;
c[t-1]=c[t-1]%n;
}

int b[n][n];
//memset(b,0,sizeof(b)*n*n);

for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
b[i][j]= a[i][(n-r[i]+j)%n] ;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]= b[(n-c[j]+i)%n][j] ;
}
}

for(int i=0;i<n;i++){
for(int j=0;j<n;j++){

cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
 
 
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