Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • 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 Magic Land problem solution

YASH PAL, 31 July 2024
In this HackerEarth Magic Land problem solution, You are given a grid of size N * M where N and M denote the number of rows and columns respectively. Each cell of the grid is filled with some number.
Now, We define a quantity called Magic Number for each row and column as the maximum number of consecutive adjacent elements having the same number. Now the password of the entry gate is defined as the MAX of MR[i]*MC[j] where MR[i] and MC[j] refer to the Magic number of ith row and jth column respectively. Can you find the password?
HackerEarth Magic Land problem solution

HackerEarth Magic Land problem solution.

#include<bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
int a[n][m];
int row = 1, col = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cin>>a[i][j];
}
}
for(int i = 0; i < n; i++) {
int num = a[i][0], count = 0;
for(int j = 0; j < m; j++) {
if(a[i][j] == num) {
count++;
row = max(row, count);
}
else {
row = max(row, count);
count = 1;
num = a[i][j];
}
}
}

for(int i = 0; i < m; i++) {
int num = a[0][i], count = 0;
for(int j = 0; j < n; j++) {
if(a[j][i] == num) {
count++;
col = max(col, count);
}
else {
col = max(col, count);
count = 1;
num = a[j][i];
}
}
}
cout<<col*row<<"n";
}
return 0;
}
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