Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • 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

HackerEarth Rubik Square problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes